RichtextModel(TextWidget) Not Working Properly with List Widget | developer.brewmp.com RichtextModel(TextWidget) Not Working Properly with List Widget | developer.brewmp.com

Developer

RichtextModel(TextWidget) Not Working Properly with List Widget

Forums:

I wanted to implement a list of text widget with Rich Text Model

1. Created a list widget and a vector model for the same.
2. Created a XY container.
3. Created a Text Widget, associated a rich text model and inserted the same into XY Container.
4. Had a value model and attached the same with XY Container.
5. XY Container is set as a decorator for List widget.
6. In the Adapt Set function, updated the text widget using the IRichTextModel Interface.
7. Gave touch support to root widget.

Note: I have few inline images in the text widget.

I just took up the rich text example which I got from the BMP Forum and updated the same to have the list.

The behavior of the text widget seems to be different with respect to the simulator. I work with Brew MP 1.0.1 SDK Rev 5.7. But the behavior what I observe in Rev 7.x is entirely different.

In the Rev 7.x, I can t move the cursor using the pointer down/up events.

In Brew MP 1.0.1 SDK Rev 5.7 simulator, for the first list item I can place the cursor wherever I want using pointer events. But rest of the cell, I can only place the cursor only at the last line. I can t move it to the previous lines.

But it can take key events. If I type something it gets displayed and I could move the cursor using key events (but it moves 4 characters at a time).

Please let us know this is a known issue.

Please find the code for the above issue, hope this will help everyone in understanding the problem...
static boolean c_RichTextEditSample_HandleEvent(c_RichTextEditSample* pMe,
AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
int px, py;
int nErr;
IWidget *temp;
WTextRange textRange = {0};
int pnStartIndex = 10;
int pnEndIndex = 10;
char *pszRTContent = NULL;
int iStartIndex = 10, iEndIndex = 10;
switch (eCode)
{
case EVT_APP_START:
c_RichTextEditSample_CreateRichTextWidget(pMe);
return(TRUE);
case EVT_APP_STOP:
return(TRUE);
case EVT_APP_SUSPEND:
return(TRUE);
case EVT_APP_RESUME:
IRootContainer_Invalidate(pMe->m_pRoot, NULL, NULL, 0);
return(TRUE);
case EVT_APP_MESSAGE:
return(TRUE);
case EVT_KEY:
switch(wParam)
{
case AVK_CLR:
IWidget_HandleEvent(pMe->piwListWidget, eCode, wParam, dwParam);
return TRUE;
case AVK_SELECT:
IWidget_HandleEvent(pMe->piwListWidget, eCode, wParam, dwParam);
break;
case AVK_LEFT:
case AVK_RIGHT:
case AVK_UP:
IWidget_HandleEvent(pMe->piListWidget, eCode, wParam, dwParam);
break;
case AVK_DOWN:
IWidget_HandleEvent(pMe->piListWidget, eCode, wParam, dwParam);
break;
default:
IWidget_HandleEvent(pMe->piwListWidget, eCode, wParam, dwParam);
return TRUE;
}
break;
case EVT_FLIP:
if(!wParam)
{
if(pMe->m_cBrewMajorVersion >= 3)
{
ISHELL_CloseApplet(pMe->applet.m_pIShell, FALSE);
}
else
{
ISHELL_CloseApplet(pMe->applet.m_pIShell, TRUE);
}
return FALSE; // return FALSE to close all apps
}
return TRUE; //flip was opened, donít terminate
case EVT_KEYGUARD:
// wParam == TRUE when keyguard is enabled
if (wParam)
{
if(pMe->m_cBrewMajorVersion >= 3)
{
ISHELL_CloseApplet(pMe->applet.m_pIShell, FALSE);
}
else
{
ISHELL_CloseApplet(pMe->applet.m_pIShell, TRUE);
}
return FALSE; // return FALSE to close all apps
}
return TRUE; // else flip/slider was opened, donít terminate
case EVT_APP_NO_SLEEP: //jtm keep the app from slowing down
return TRUE;
default:
break;
}
if(NULL != pMe->m_pwRoot)
{
return IWidget_HandleEvent(pMe->m_pwRoot, eCode, wParam, dwParam); //Give the event to the root one...it will delegate the event.
}
else
{
return FALSE;
}

static int c_RichTextEditSample_CreateRichTextWidget(c_RichTextEditSample *pMe)
{
WidgetExtent we;
AEEResult nErr = AEE_SUCCESS;
WidgetPos wpos;
AECHAR szMarkupText[] = L" Jeffrey T. Kiltman #[blue] (858) 555-1234 [/blue] ravindran.chandra@gmail.com ";
int i = 0;
SETAEERECT(&pMe->rcContainer, 0, 0, (short) pMe->deviceInfo.cxScreen, (short) pMe->deviceInfo.cyScreen);
ERR_TRY( ISHELL_CreateInstance(pMe->piShell, AEECLSID_RootContainer, (void**)&pMe->m_pRoot) );
ERR_TRY( ISHELL_CreateInstance(pMe->piShell, AEECLSID_DisplayCanvas, (void**)&pMe->m_pCanvas) );
ERR_TRY( IDisplayCanvas_SetDisplay(pMe->m_pCanvas, pMe->piDisplay) );
IRootContainer_QueryInterface(pMe->m_pRoot,AEEIID_IWidget ,&pMe->m_pwRoot );
IRootContainer_SetCanvas(pMe->m_pRoot, (ICanvas*) (void*) pMe->m_pCanvas,&pMe->rcContainer );
pMe->m_pBackgroundImage = ISHELL_LoadImage(pMe->piShell, "kilt_contact.png");
ERR_TRY( ISHELL_CreateInstance(pMe->piShell, AEECLSID_ImageWidget,(void**)&pMe->m_pBackgroundImageWidget) );
ERR_TRY( IWidget_SetImage(pMe->m_pBackgroundImageWidget, pMe->m_pBackgroundImage) );
RELEASEIF(pMe->m_pBackgroundImage);
ERR_TRY( IWidget_SetFlags(pMe->m_pBackgroundImageWidget, IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE) );
IWidget_GetPreferredExtent(pMe->m_pBackgroundImageWidget, &we);
IWidget_SetExtent(pMe->m_pBackgroundImageWidget, &we);
wpos.bVisible = TRUE;
wpos.x = 0;
wpos.y = 0;
ERR_TRY(IRootContainer_Insert(pMe->m_pRoot, pMe->m_pBackgroundImageWidget, WIDGET_ZNORMAL, &wpos));
ERR_TRY( ISHELL_CreateInstance(pMe->piShell, AEECLSID_ListWidget, (void**)&(pMe->piListWidget)) );
ERR_TRY( IWidget_QueryInterface(pMe->piListWidget, AEEIID_IWidget, (void**) &(pMe->piwListWidget)) );
ERR_TRY( ISHELL_CreateInstance(pMe->piShell, AEECLSID_VectorModel, (void**)&(pMe->iVector)) );
ERR_TRY( IWidget_SetModel(pMe->piwListWidget,(IModel*)pMe->iVector) );
we.height = 320;
we.width = 240;
(void)IWidget_SetExtent(pMe->piwListWidget, &we);
nErr = ISHELL_CreateInstance(pMe->piShell, AEECLSID_XYContainer, (void **)&pMe->piItemCont);
nErr = IXYCONTAINER_QueryInterface(pMe->piItemCont, AEEIID_WIDGET, (void **)&pMe->piwItemCont);
we.height = 150;
we.width = 223;
(void)IWidget_SetExtent(pMe->piwItemCont, &we);
nErr = ISHELL_CreateInstance(pMe->piShell, AEECLSID_ValueModel, (void **)&(pMe->iValueModel));
nErr = IWidget_SetModel(pMe->piwItemCont, (IModel *)pMe->iValueModel);
IVALUEMODEL_AdaptSet(pMe->iValueModel, ListItemAdaptSet, pMe);
(void) IDECORATOR_SetWidget((IDecorator*)pMe->piListWidget, pMe->piwItemCont);
IWidget_SetItemHeight(pMe->piwListWidget, 150);
ERR_TRY( ISHELL_CreateInstance(pMe->piShell, AEECLSID_TextWidget, CAST(void**, &pMe->m_pRichTextElement)));
ERR_TRY( ISHELL_CreateInstance(pMe->piShell, AEECLSID_TextModel, CAST(void**, &pMe->m_pTextModel)));
ModelListener_InitEx(&(pMe->pListener), (PFNLISTENER)c_RichTextEditSample_app_ListListen, pMe);
ITextModel_AddListener(pMe->m_pTextModel, &(pMe->pListener));
ERR_TRY( ITextModel_QueryInterface(pMe->m_pTextModel, AEEIID_IRichTextModel, (void **) &pMe->m_pRichTextModel));
ERR_TRY(IWidget_SetModel(pMe->m_pRichTextElement, (IModel *)pMe->m_pRichTextModel));
ERR_TRY(IWidget_SetFlags(pMe->m_pRichTextElement, TWF_MULTILINE));
c_RichTextEditSample_SetRichTextFonts(pMe);
for (i = 0; i <2; i++)
{
IVectorModel_InsertAt(pMe->iVector, i, (void *)i);
}
{
WidgetExtent we;
we.height = 150;
we.width = 223;
IWidget_SetExtent(pMe->m_pRichTextElement, &we);
}
wpos.x = 2;
wpos.y = 0;
wpos.bVisible=TRUE;
IXYContainer_Insert(pMe->piItemCont, pMe->m_pRichTextElement, WIDGET_ZNORMAL, &wpos);
IWidget_EnableTouch(pMe->m_pwRoot);
wpos.x = 0;
wpos.y = 0;
wpos.bVisible = TRUE;
ERR_TRY(IRootContainer_Insert(pMe->m_pRoot, pMe->piwListWidget, WIDGET_ZNORMAL, &wpos));
IWidget_SetFocus(pMe->piwListWidget,TRUE);
HANDLERDESC_INIT(&pMe->hdListItemWidgetHandler, ListItem_HandleEvent, pMe, NULL);
(void)IWidget_SetHandler(pMe->m_pRichTextElement, &pMe->hdListItemWidgetHandler);
HANDLERDESC_INIT(&pMe->hdListWidgetHandler, List_HandleEvent, pMe, NULL);
(void)IWidget_SetHandler(pMe->piListWidget, &pMe->hdListWidgetHandler);
ERR_CATCH:
if (AEE_SUCCESS != nErr)
{
RELEASEIF(pMe->m_pRichTextModel);
RELEASEIF(pMe->m_pRichTextElement);
RELEASEIF(pMe->m_pCanvas);
RELEASEIF(pMe->m_pRoot);
}
return nErr;

static int c_RichTextEditSample_SetRichTextFonts(c_RichTextEditSample* pMe)
{
int nErr = SUCCESS;
pMe->wSize = 12; //12 point for default
ERR_TRY(ISHELL_CreateInstance(pMe->piShell, AEECLSID_FONTMAPMODEL, (void**)&pMe->m_piFontMapModel));
ERR_TRY(ISHELL_CreateInstance(pMe->piShell, AEECLSID_TYPEFACE, (void**)&pMe->m_pitf));
// default font
ERR_TRY(ITypeface_NewFontFromFontFile(pMe->m_pitf, "qcsans.ttf", pMe->wSize, &pMe->m_pihf));
ERR_TRY(c_RichTextEditSample_SetInlineImages(pMe, pMe->m_pihf));
ERR_TRY(IFontMapModel_Insert(pMe->m_piFontMapModel, NULL, CAST(IFont*, pMe->m_pihf)));
RELEASEIF(pMe->m_pihf);
// [b] == bold font
pMe->wSize = 12;
ERR_TRY(ITypeface_NewFontFromFontFile(pMe->m_pitf, "qcsans.ttf", pMe->wSize, &pMe->m_pihf));
ERR_TRY(c_RichTextEditSample_SetStyle(pMe, CAST(IFont*, pMe->m_pihf)));
ERR_TRY(IHFont_SetEmphasisStyle(pMe->m_pihf, HFONT_EMPHASIS_BOLD));
ERR_TRY(IFontMapModel_Insert(pMe->m_piFontMapModel, pawMarkupBold, CAST(IFont*, pMe->m_pihf)));
RELEASEIF(pMe->m_pihf);
pMe->wSize = 12;
// [i] = italic font
ERR_TRY(ITypeface_NewFontFromFontFile(pMe->m_pitf, "qcsans.ttf", pMe->wSize, &pMe->m_pihf));
ERR_TRY(c_RichTextEditSample_SetStyle(pMe, CAST(IFont*, pMe->m_pihf)));
ERR_TRY(IHFont_SetEmphasisStyle(pMe->m_pihf, HFONT_EMPHASIS_ITALIC));
ERR_TRY(IFontMapModel_Insert(pMe->m_piFontMapModel, pawMarkupItalic, CAST(IFont*, pMe->m_pihf)));
RELEASEIF(pMe->m_pihf);
// [blue] == blue font
pMe->wSize = 12;
ERR_TRY(ITypeface_NewFontFromFontFile(pMe->m_pitf, "qcsans.ttf", pMe->wSize, &pMe->m_pihf));
ERR_TRY(c_RichTextEditSample_SetStyle(pMe, CAST(IFont*, pMe->m_pihf)));
ERR_TRY(IHFont_SetTextColor(pMe->m_pihf, RGBA_BLUE));
ERR_TRY(IFontMapModel_Insert(pMe->m_piFontMapModel, pawMarkupBlue, CAST(IFont*, pMe->m_pihf)));
RELEASEIF(pMe->m_pihf);
// [u] == underlined
pMe->wSize = 12;
ERR_TRY(ITypeface_NewFontFromFontFile(pMe->m_pitf, "qcsans.ttf", pMe->wSize, &pMe->m_pihf));
ERR_TRY(c_RichTextEditSample_SetStyle(pMe, CAST(IFont*, pMe->m_pihf)));
ERR_TRY(IHFont_SetUnderlineStyle(pMe->m_pihf, HFONT_LINEEFFECT_SINGLE));
ERR_TRY(IHFont_SetTextColor(pMe->m_pihf, RGBA_RED));
ERR_TRY(IFontMapModel_Insert(pMe->m_piFontMapModel, pawMarkupUnderlined, CAST(IFont*, pMe->m_pihf)));
RELEASEIF(pMe->m_pihf);
ERR_TRY(ITextLayout_SetFontMapModel((ITextLayout *)pMe->m_pRichTextElement, pMe->m_piFontMapModel));
ERR_TRY(IWidget_SetTextLayoutClassId(pMe->m_pRichTextElement, AEECLSID_BTFETextLayout ));
ERR_CATCH:
if (AEE_SUCCESS != nErr)
{
RELEASEIF(pMe->m_piFontMapModel);
RELEASEIF(pMe->m_pihf);
}
return nErr;

static int c_RichTextEditSample_SetStyle(c_RichTextEditSample* pMe, IFont* pif)
{
int nErr = SUCCESS;
IHFont* pihf = NULL;
nErr = IFont_to_IHFont((IFont*)pif, &pihf);
if (SUCCESS != nErr) goto cleanup;
// style text
nErr = IHFont_SetEmphasisStyle(pihf, pMe->nEmphasisStyle);
if (SUCCESS != nErr) goto cleanup;
nErr = IHFont_SetEdgeStyle(pihf, pMe->nEdgeStyle);
if (SUCCESS != nErr) goto cleanup;
// adorn text
nErr = IHFont_SetTextColor(pihf, gTestColors[pMe->nTextColor]);
if (SUCCESS != nErr) goto cleanup;
nErr = IHFont_SetEdgeColor(pihf, gTestColors[pMe->nEdgeColor]);
if (SUCCESS != nErr) goto cleanup;
nErr = IHFont_SetFontOutlineWidth(pihf, pMe->nOutlineWidth);
if (SUCCESS != nErr) goto cleanup;
// set line effect
nErr = IHFont_SetUnderlineStyle(pihf, 0);
if (SUCCESS != nErr) goto cleanup;
nErr = IHFont_SetStrikeoutStyle(pihf, 0);
if (SUCCESS != nErr) goto cleanup;
nErr = IHFont_SetOverlineStyle(pihf, 0);
if (SUCCESS != nErr) goto cleanup;
cleanup:
RELEASEIF(pihf);
return nErr;

static void c_RichTextEditSample_InlineImageDrawCB(InlineImageInfo* piii)
{
c_RichTextEditSample* pMe = piii->pUserData;
IImage_Draw(pMe->m_pInlineImage, piii->rcDst.x, piii->rcDst.y);

static int c_RichTextEditSample_SetInlineImages(c_RichTextEditSample* pMe, IHFont* pihf)
{
int nErr = SUCCESS;
AEEImageInfo ii;
InlineImageParam* piip = &pMe->m_piip;
pMe->m_pInlineImage = ISHELL_LoadImage(pMe->piShell, "smiley.png");
IIMAGE_GetInfo(pMe->m_pInlineImage, &ii);
// place emoticons 3 pixels below the baseline
SETAEERECT(&piip->rcImage, 0, 0, ii.cxFrame, ii.cy);
piip->dcb = c_RichTextEditSample_InlineImageDrawCB;
piip->pUser = (void*)pMe;
piip->dwImageId = 0;
piip->dwCharCode = (int)(AECHAR)'#';
nErr = IHFont_SetInlineImageParam(pihf, &pMe->m_piip);
return nErr;

static int c_RichTextEditSample_ReplaceInlineImages(c_RichTextEditSample* pMe, IHFont* pihf)
{
int nErr = SUCCESS;
AEEImageInfo ii;
InlineImageParam* piip = &pMe->m_piip;
pMe->m_pInlineImage = ISHELL_LoadImage(pMe->piShell, "contact.png");
IIMAGE_GetInfo(pMe->m_pInlineImage, &ii);
// place emoticons 3 pixels below the baseline
SETAEERECT(&piip->rcImage, 0, 0, ii.cxFrame, ii.cy);
piip->dcb = c_RichTextEditSample_InlineImageDrawCB;
piip->pUser = (void*)pMe;
piip->dwImageId = 0;
piip->dwCharCode = (int)(AECHAR)'#';
nErr = IHFont_SetInlineImageParam(pihf, &pMe->m_piip);
return nErr;

static void c_RichTextEditSample_app_ListListen(c_RichTextEditSample* pMe, ModelEvent* pEvt)
{
int pnStartIndex, pnEndIndex, nErr;
char *pszRTContent = NULL;
int iStartIndex = 10, iEndIndex = 10, nListIndex;
if (pEvt->evCode == EVT_MDL_TEXT_CHANGE)
{
ScrollEvent* pse = CAST(ScrollEvent*, pEvt);
DBGPRINTF_LOW("EVT_MDL_TEXT_CHANGE");
}
else if (pEvt->evCode == EVT_MDL_TEXT_SELECT)
{
FocusEvent* pfe = (FocusEvent*)pEvt;
DBGPRINTF_LOW("EVT_MDL_TEXT_SELECT");
}
else if (pEvt->evCode == EVT_MDL_SCROLL_CHANGE)
{
FocusEvent* pfe = (FocusEvent*)pEvt;
DBGPRINTF_LOW("EVT_MDL_SCROLL_CHANGE");
}

void app_ngm_convthread_findurlstr(TextInfo *pstTextInfo, char **pURLString)
{
char *pszTempChar = NULL;
char *pszOutBuf = NULL;
char *pszCharStart = NULL, *pszCharEnd = NULL;
uint8 uiCharCount1 = 0, uiCharCount2 = 0;
char *pszReqEnd = NULL, *pszReqStart = NULL;
pszTempChar = (char *) MALLOC(pstTextInfo->cchText + 1);
WSTRTOSTR(pstTextInfo->pwText, pszTempChar, pstTextInfo->cchText);
pszCharStart = pszTempChar + pstTextInfo->nSelStart;
pszReqEnd = STRCHR(pszCharStart, ' ');
uiCharCount2 = pszReqEnd - pszCharStart;
*(pszTempChar + pstTextInfo->nSelStart) = '\0';
strrev(pszTempChar);
pszReqStart = STRCHR(pszTempChar, ' ');
uiCharCount1 = pszReqStart - pszTempChar;
pstTextInfo->nSelStart = pstTextInfo->nSelStart - uiCharCount1;
WSTRTOSTR(pstTextInfo->pwText, pszTempChar, pstTextInfo->cchText);
pszOutBuf = (char *) MALLOC( uiCharCount1 + uiCharCount2 + 1);
STRNCPY(pszOutBuf, (pszTempChar + pstTextInfo->nSelStart), uiCharCount1 + uiCharCount2 );
*pURLString = pszOutBuf;

void ListItemAdaptSet(void *pvCtx, void *pValueIn, int nLen, void **ppValueOut, int *pnLenOut, PFNVALUEFREE *ppfn)
{
c_RichTextEditSample *pMe = pvCtx;
AECHAR szMarkupText[] = L"\n # \n[blue] (858) 555-1234 [/blue]\n eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%61%62%63%64%65%66%2e%67%68%69%6a%6b%6c%40%6d%6e%6f%70%71%2e%63%6f%6d%22%3e%61%62%63%64%65%66%2e%67%68%69%6a%6b%6c%40%6d%6e%6f%70%71%2e%63%6f%6d%3c%2f%61%3e%27%29%3b')) ";
IRichTextModel *pRichValMdl;
ITextModel *pValMdl;
WidgetPos wpos;
int nErr;
if ( NULL == pValueIn) return;
if(NULL != pMe->m_pRichTextElement)
{
ERR_TRY(IWidget_GetModel(pMe->m_pRichTextElement, AEEIID_ITextModel,(IModel **)&pValMdl));
ERR_TRY( ITextModel_QueryInterface(pValMdl, AEEIID_IRichTextModel, (void **) &pRichValMdl));
IRichTextModel_SetMarkupText(pRichValMdl, szMarkupText, -1);
IRichTextModel_Release(pRichValMdl);
ITextModel_Release(pValMdl);
}
ERR_CATCH:
return;
}
static boolean List_HandleEvent(void *po, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
c_RichTextEditSample * pMe = (c_RichTextEditSample *)po;
boolean bhandled = AEE_EFAILED;
switch (eCode)
{
default:
bhandled = IWidget_HandleEvent(pMe->m_pRichTextElement, eCode, wParam, dwParam);
break; // Event to inform app to start, so start-up code is here:
}
bhandled = HANDLERDESC_CALL(&pMe->hdListWidgetHandler, eCode, wParam, dwParam);
return bhandled;

static boolean ListItem_HandleEvent(void *po, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
c_RichTextEditSample * pMe = (c_RichTextEditSample *)po;
boolean bhandled = AEE_EFAILED;
int pnStartIndex, pnEndIndex, nErr;
char *pszRTContent = NULL;
int iStartIndex = 10, iEndIndex = 10, nListIndex;
switch (eCode)
{
case EVT_POINTER_DOWN:
{
DBGPRINTF_LOW("POINTER DOWN");
}
break;
case EVT_POINTER_UP:
{
DBGPRINTF_LOW("POINTER UP");
}
break;
}
bhandled = HANDLERDESC_CALL(&pMe->hdListItemWidgetHandler, eCode, wParam, dwParam);
if (EVT_POINTER_UP == eCode)
{
ITextModel_GetTextInfo(pMe->m_pTextModel, &pMe->pTextInfo);
DBGPRINTF("Index is %d",pMe->pTextInfo.nSelStart);
DBGPRINTF("Current Char is %c",pMe->pTextInfo.pwText[pMe->pTextInfo.nSelStart]);
IWIDGET_GetFocusIndex(pMe->piwListWidget,&nListIndex);
DBGPRINTF("List Index is %d",nListIndex);
if ('#' == pMe->pTextInfo.pwText[pMe->pTextInfo.nSelStart])
{
ITextModel_SetSel(pMe->m_pTextModel,(pMe->pTextInfo.nSelStart)-1,(pMe->pTextInfo.nSelEndCaret)+2);
}
else
{
ITextModel_SetSel(pMe->m_pTextModel,(pMe->pTextInfo.nSelStart),(pMe->pTextInfo.nSelEndCaret)+1);
}
}
return bhandled;

Please find the code for the above issue, hope this will help everyone in understanding the problem...
static boolean c_RichTextEditSample_HandleEvent(c_RichTextEditSample* pMe,
AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
int px, py;
int nErr;
IWidget *temp;
WTextRange textRange = {0};
int pnStartIndex = 10;
int pnEndIndex = 10;
char *pszRTContent = NULL;
int iStartIndex = 10, iEndIndex = 10;
switch (eCode)
{
case EVT_APP_START:
c_RichTextEditSample_CreateRichTextWidget(pMe);
return(TRUE);
case EVT_APP_STOP:
return(TRUE);
case EVT_APP_SUSPEND:
return(TRUE);
case EVT_APP_RESUME:
IRootContainer_Invalidate(pMe->m_pRoot, NULL, NULL, 0);
return(TRUE);
case EVT_APP_MESSAGE:
return(TRUE);
case EVT_KEY:
switch(wParam)
{
case AVK_CLR:
IWidget_HandleEvent(pMe->piwListWidget, eCode, wParam, dwParam);
return TRUE;
case AVK_SELECT:
IWidget_HandleEvent(pMe->piwListWidget, eCode, wParam, dwParam);
break;
case AVK_LEFT:
case AVK_RIGHT:
case AVK_UP:
IWidget_HandleEvent(pMe->piListWidget, eCode, wParam, dwParam);
break;
case AVK_DOWN:
IWidget_HandleEvent(pMe->piListWidget, eCode, wParam, dwParam);
break;
default:
IWidget_HandleEvent(pMe->piwListWidget, eCode, wParam, dwParam);
return TRUE;
}
break;
case EVT_FLIP:
if(!wParam)
{
if(pMe->m_cBrewMajorVersion >= 3)
{
ISHELL_CloseApplet(pMe->applet.m_pIShell, FALSE);
}
else
{
ISHELL_CloseApplet(pMe->applet.m_pIShell, TRUE);
}
return FALSE; // return FALSE to close all apps
}
return TRUE; //flip was opened, donít terminate
case EVT_KEYGUARD:
// wParam == TRUE when keyguard is enabled
if (wParam)
{
if(pMe->m_cBrewMajorVersion >= 3)
{
ISHELL_CloseApplet(pMe->applet.m_pIShell, FALSE);
}
else
{
ISHELL_CloseApplet(pMe->applet.m_pIShell, TRUE);
}
return FALSE; // return FALSE to close all apps
}
return TRUE; // else flip/slider was opened, donít terminate
case EVT_APP_NO_SLEEP: //jtm keep the app from slowing down
return TRUE;
default:
break;
}
if(NULL != pMe->m_pwRoot)
{
return IWidget_HandleEvent(pMe->m_pwRoot, eCode, wParam, dwParam); //Give the event to the root one...it will delegate the event.
}
else
{
return FALSE;
}

static int c_RichTextEditSample_CreateRichTextWidget(c_RichTextEditSample *pMe)
{
WidgetExtent we;
AEEResult nErr = AEE_SUCCESS;
WidgetPos wpos;
AECHAR szMarkupText[] = L" Jeffrey T. Kiltman #[blue] (858) 555-1234 [/blue] ravindran.chandra@gmail.com ";
int i = 0;
SETAEERECT(&pMe->rcContainer, 0, 0, (short) pMe->deviceInfo.cxScreen, (short) pMe->deviceInfo.cyScreen);
ERR_TRY( ISHELL_CreateInstance(pMe->piShell, AEECLSID_RootContainer, (void**)&pMe->m_pRoot) );
ERR_TRY( ISHELL_CreateInstance(pMe->piShell, AEECLSID_DisplayCanvas, (void**)&pMe->m_pCanvas) );
ERR_TRY( IDisplayCanvas_SetDisplay(pMe->m_pCanvas, pMe->piDisplay) );
IRootContainer_QueryInterface(pMe->m_pRoot,AEEIID_IWidget ,&pMe->m_pwRoot );
IRootContainer_SetCanvas(pMe->m_pRoot, (ICanvas*) (void*) pMe->m_pCanvas,&pMe->rcContainer );
pMe->m_pBackgroundImage = ISHELL_LoadImage(pMe->piShell, "kilt_contact.png");
ERR_TRY( ISHELL_CreateInstance(pMe->piShell, AEECLSID_ImageWidget,(void**)&pMe->m_pBackgroundImageWidget) );
ERR_TRY( IWidget_SetImage(pMe->m_pBackgroundImageWidget, pMe->m_pBackgroundImage) );
RELEASEIF(pMe->m_pBackgroundImage);
ERR_TRY( IWidget_SetFlags(pMe->m_pBackgroundImageWidget, IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE) );
IWidget_GetPreferredExtent(pMe->m_pBackgroundImageWidget, &we);
IWidget_SetExtent(pMe->m_pBackgroundImageWidget, &we);
wpos.bVisible = TRUE;
wpos.x = 0;
wpos.y = 0;
ERR_TRY(IRootContainer_Insert(pMe->m_pRoot, pMe->m_pBackgroundImageWidget, WIDGET_ZNORMAL, &wpos));
ERR_TRY( ISHELL_CreateInstance(pMe->piShell, AEECLSID_ListWidget, (void**)&(pMe->piListWidget)) );
ERR_TRY( IWidget_QueryInterface(pMe->piListWidget, AEEIID_IWidget, (void**) &(pMe->piwListWidget)) );
ERR_TRY( ISHELL_CreateInstance(pMe->piShell, AEECLSID_VectorModel, (void**)&(pMe->iVector)) );
ERR_TRY( IWidget_SetModel(pMe->piwListWidget,(IModel*)pMe->iVector) );
we.height = 320;
we.width = 240;
(void)IWidget_SetExtent(pMe->piwListWidget, &we);
nErr = ISHELL_CreateInstance(pMe->piShell, AEECLSID_XYContainer, (void **)&pMe->piItemCont);
nErr = IXYCONTAINER_QueryInterface(pMe->piItemCont, AEEIID_WIDGET, (void **)&pMe->piwItemCont);
we.height = 150;
we.width = 223;
(void)IWidget_SetExtent(pMe->piwItemCont, &we);
nErr = ISHELL_CreateInstance(pMe->piShell, AEECLSID_ValueModel, (void **)&(pMe->iValueModel));
nErr = IWidget_SetModel(pMe->piwItemCont, (IModel *)pMe->iValueModel);
IVALUEMODEL_AdaptSet(pMe->iValueModel, ListItemAdaptSet, pMe);
(void) IDECORATOR_SetWidget((IDecorator*)pMe->piListWidget, pMe->piwItemCont);
IWidget_SetItemHeight(pMe->piwListWidget, 150);
ERR_TRY( ISHELL_CreateInstance(pMe->piShell, AEECLSID_TextWidget, CAST(void**, &pMe->m_pRichTextElement)));
ERR_TRY( ISHELL_CreateInstance(pMe->piShell, AEECLSID_TextModel, CAST(void**, &pMe->m_pTextModel)));
ModelListener_InitEx(&(pMe->pListener), (PFNLISTENER)c_RichTextEditSample_app_ListListen, pMe);
ITextModel_AddListener(pMe->m_pTextModel, &(pMe->pListener));
ERR_TRY( ITextModel_QueryInterface(pMe->m_pTextModel, AEEIID_IRichTextModel, (void **) &pMe->m_pRichTextModel));
ERR_TRY(IWidget_SetModel(pMe->m_pRichTextElement, (IModel *)pMe->m_pRichTextModel));
ERR_TRY(IWidget_SetFlags(pMe->m_pRichTextElement, TWF_MULTILINE));
c_RichTextEditSample_SetRichTextFonts(pMe);
for (i = 0; i <2; i++)
{
IVectorModel_InsertAt(pMe->iVector, i, (void *)i);
}
{
WidgetExtent we;
we.height = 150;
we.width = 223;
IWidget_SetExtent(pMe->m_pRichTextElement, &we);
}
wpos.x = 2;
wpos.y = 0;
wpos.bVisible=TRUE;
IXYContainer_Insert(pMe->piItemCont, pMe->m_pRichTextElement, WIDGET_ZNORMAL, &wpos);
IWidget_EnableTouch(pMe->m_pwRoot);
wpos.x = 0;
wpos.y = 0;
wpos.bVisible = TRUE;
ERR_TRY(IRootContainer_Insert(pMe->m_pRoot, pMe->piwListWidget, WIDGET_ZNORMAL, &wpos));
IWidget_SetFocus(pMe->piwListWidget,TRUE);
HANDLERDESC_INIT(&pMe->hdListItemWidgetHandler, ListItem_HandleEvent, pMe, NULL);
(void)IWidget_SetHandler(pMe->m_pRichTextElement, &pMe->hdListItemWidgetHandler);
HANDLERDESC_INIT(&pMe->hdListWidgetHandler, List_HandleEvent, pMe, NULL);
(void)IWidget_SetHandler(pMe->piListWidget, &pMe->hdListWidgetHandler);
ERR_CATCH:
if (AEE_SUCCESS != nErr)
{
RELEASEIF(pMe->m_pRichTextModel);
RELEASEIF(pMe->m_pRichTextElement);
RELEASEIF(pMe->m_pCanvas);
RELEASEIF(pMe->m_pRoot);
}
return nErr;

static int c_RichTextEditSample_SetRichTextFonts(c_RichTextEditSample* pMe)
{
int nErr = SUCCESS;
pMe->wSize = 12; //12 point for default
ERR_TRY(ISHELL_CreateInstance(pMe->piShell, AEECLSID_FONTMAPMODEL, (void**)&pMe->m_piFontMapModel));
ERR_TRY(ISHELL_CreateInstance(pMe->piShell, AEECLSID_TYPEFACE, (void**)&pMe->m_pitf));
// default font
ERR_TRY(ITypeface_NewFontFromFontFile(pMe->m_pitf, "qcsans.ttf", pMe->wSize, &pMe->m_pihf));
ERR_TRY(c_RichTextEditSample_SetInlineImages(pMe, pMe->m_pihf));
ERR_TRY(IFontMapModel_Insert(pMe->m_piFontMapModel, NULL, CAST(IFont*, pMe->m_pihf)));
RELEASEIF(pMe->m_pihf);
// [b] == bold font
pMe->wSize = 12;
ERR_TRY(ITypeface_NewFontFromFontFile(pMe->m_pitf, "qcsans.ttf", pMe->wSize, &pMe->m_pihf));
ERR_TRY(c_RichTextEditSample_SetStyle(pMe, CAST(IFont*, pMe->m_pihf)));
ERR_TRY(IHFont_SetEmphasisStyle(pMe->m_pihf, HFONT_EMPHASIS_BOLD));
ERR_TRY(IFontMapModel_Insert(pMe->m_piFontMapModel, pawMarkupBold, CAST(IFont*, pMe->m_pihf)));
RELEASEIF(pMe->m_pihf);
pMe->wSize = 12;
// [i] = italic font
ERR_TRY(ITypeface_NewFontFromFontFile(pMe->m_pitf, "qcsans.ttf", pMe->wSize, &pMe->m_pihf));
ERR_TRY(c_RichTextEditSample_SetStyle(pMe, CAST(IFont*, pMe->m_pihf)));
ERR_TRY(IHFont_SetEmphasisStyle(pMe->m_pihf, HFONT_EMPHASIS_ITALIC));
ERR_TRY(IFontMapModel_Insert(pMe->m_piFontMapModel, pawMarkupItalic, CAST(IFont*, pMe->m_pihf)));
RELEASEIF(pMe->m_pihf);
// [blue] == blue font
pMe->wSize = 12;
ERR_TRY(ITypeface_NewFontFromFontFile(pMe->m_pitf, "qcsans.ttf", pMe->wSize, &pMe->m_pihf));
ERR_TRY(c_RichTextEditSample_SetStyle(pMe, CAST(IFont*, pMe->m_pihf)));
ERR_TRY(IHFont_SetTextColor(pMe->m_pihf, RGBA_BLUE));
ERR_TRY(IFontMapModel_Insert(pMe->m_piFontMapModel, pawMarkupBlue, CAST(IFont*, pMe->m_pihf)));
RELEASEIF(pMe->m_pihf);
// [u] == underlined
pMe->wSize = 12;
ERR_TRY(ITypeface_NewFontFromFontFile(pMe->m_pitf, "qcsans.ttf", pMe->wSize, &pMe->m_pihf));
ERR_TRY(c_RichTextEditSample_SetStyle(pMe, CAST(IFont*, pMe->m_pihf)));
ERR_TRY(IHFont_SetUnderlineStyle(pMe->m_pihf, HFONT_LINEEFFECT_SINGLE));
ERR_TRY(IHFont_SetTextColor(pMe->m_pihf, RGBA_RED));
ERR_TRY(IFontMapModel_Insert(pMe->m_piFontMapModel, pawMarkupUnderlined, CAST(IFont*, pMe->m_pihf)));
RELEASEIF(pMe->m_pihf);
ERR_TRY(ITextLayout_SetFontMapModel((ITextLayout *)pMe->m_pRichTextElement, pMe->m_piFontMapModel));
ERR_TRY(IWidget_SetTextLayoutClassId(pMe->m_pRichTextElement, AEECLSID_BTFETextLayout ));
ERR_CATCH:
if (AEE_SUCCESS != nErr)
{
RELEASEIF(pMe->m_piFontMapModel);
RELEASEIF(pMe->m_pihf);
}
return nErr;

static int c_RichTextEditSample_SetStyle(c_RichTextEditSample* pMe, IFont* pif)
{
int nErr = SUCCESS;
IHFont* pihf = NULL;
nErr = IFont_to_IHFont((IFont*)pif, &pihf);
if (SUCCESS != nErr) goto cleanup;
// style text
nErr = IHFont_SetEmphasisStyle(pihf, pMe->nEmphasisStyle);
if (SUCCESS != nErr) goto cleanup;
nErr = IHFont_SetEdgeStyle(pihf, pMe->nEdgeStyle);
if (SUCCESS != nErr) goto cleanup;
// adorn text
nErr = IHFont_SetTextColor(pihf, gTestColors[pMe->nTextColor]);
if (SUCCESS != nErr) goto cleanup;
nErr = IHFont_SetEdgeColor(pihf, gTestColors[pMe->nEdgeColor]);
if (SUCCESS != nErr) goto cleanup;
nErr = IHFont_SetFontOutlineWidth(pihf, pMe->nOutlineWidth);
if (SUCCESS != nErr) goto cleanup;
// set line effect
nErr = IHFont_SetUnderlineStyle(pihf, 0);
if (SUCCESS != nErr) goto cleanup;
nErr = IHFont_SetStrikeoutStyle(pihf, 0);
if (SUCCESS != nErr) goto cleanup;
nErr = IHFont_SetOverlineStyle(pihf, 0);
if (SUCCESS != nErr) goto cleanup;
cleanup:
RELEASEIF(pihf);
return nErr;

static void c_RichTextEditSample_InlineImageDrawCB(InlineImageInfo* piii)
{
c_RichTextEditSample* pMe = piii->pUserData;
IImage_Draw(pMe->m_pInlineImage, piii->rcDst.x, piii->rcDst.y);

static int c_RichTextEditSample_SetInlineImages(c_RichTextEditSample* pMe, IHFont* pihf)
{
int nErr = SUCCESS;
AEEImageInfo ii;
InlineImageParam* piip = &pMe->m_piip;
pMe->m_pInlineImage = ISHELL_LoadImage(pMe->piShell, "smiley.png");
IIMAGE_GetInfo(pMe->m_pInlineImage, &ii);
// place emoticons 3 pixels below the baseline
SETAEERECT(&piip->rcImage, 0, 0, ii.cxFrame, ii.cy);
piip->dcb = c_RichTextEditSample_InlineImageDrawCB;
piip->pUser = (void*)pMe;
piip->dwImageId = 0;
piip->dwCharCode = (int)(AECHAR)'#';
nErr = IHFont_SetInlineImageParam(pihf, &pMe->m_piip);
return nErr;

static int c_RichTextEditSample_ReplaceInlineImages(c_RichTextEditSample* pMe, IHFont* pihf)
{
int nErr = SUCCESS;
AEEImageInfo ii;
InlineImageParam* piip = &pMe->m_piip;
pMe->m_pInlineImage = ISHELL_LoadImage(pMe->piShell, "contact.png");
IIMAGE_GetInfo(pMe->m_pInlineImage, &ii);
// place emoticons 3 pixels below the baseline
SETAEERECT(&piip->rcImage, 0, 0, ii.cxFrame, ii.cy);
piip->dcb = c_RichTextEditSample_InlineImageDrawCB;
piip->pUser = (void*)pMe;
piip->dwImageId = 0;
piip->dwCharCode = (int)(AECHAR)'#';
nErr = IHFont_SetInlineImageParam(pihf, &pMe->m_piip);
return nErr;

static void c_RichTextEditSample_app_ListListen(c_RichTextEditSample* pMe, ModelEvent* pEvt)
{
int pnStartIndex, pnEndIndex, nErr;
char *pszRTContent = NULL;
int iStartIndex = 10, iEndIndex = 10, nListIndex;
if (pEvt->evCode == EVT_MDL_TEXT_CHANGE)
{
ScrollEvent* pse = CAST(ScrollEvent*, pEvt);
DBGPRINTF_LOW("EVT_MDL_TEXT_CHANGE");
}
else if (pEvt->evCode == EVT_MDL_TEXT_SELECT)
{
FocusEvent* pfe = (FocusEvent*)pEvt;
DBGPRINTF_LOW("EVT_MDL_TEXT_SELECT");
}
else if (pEvt->evCode == EVT_MDL_SCROLL_CHANGE)
{
FocusEvent* pfe = (FocusEvent*)pEvt;
DBGPRINTF_LOW("EVT_MDL_SCROLL_CHANGE");
}

void app_ngm_convthread_findurlstr(TextInfo *pstTextInfo, char **pURLString)
{
char *pszTempChar = NULL;
char *pszOutBuf = NULL;
char *pszCharStart = NULL, *pszCharEnd = NULL;
uint8 uiCharCount1 = 0, uiCharCount2 = 0;
char *pszReqEnd = NULL, *pszReqStart = NULL;
pszTempChar = (char *) MALLOC(pstTextInfo->cchText + 1);
WSTRTOSTR(pstTextInfo->pwText, pszTempChar, pstTextInfo->cchText);
pszCharStart = pszTempChar + pstTextInfo->nSelStart;
pszReqEnd = STRCHR(pszCharStart, ' ');
uiCharCount2 = pszReqEnd - pszCharStart;
*(pszTempChar + pstTextInfo->nSelStart) = '\0';
strrev(pszTempChar);
pszReqStart = STRCHR(pszTempChar, ' ');
uiCharCount1 = pszReqStart - pszTempChar;
pstTextInfo->nSelStart = pstTextInfo->nSelStart - uiCharCount1;
WSTRTOSTR(pstTextInfo->pwText, pszTempChar, pstTextInfo->cchText);
pszOutBuf = (char *) MALLOC( uiCharCount1 + uiCharCount2 + 1);
STRNCPY(pszOutBuf, (pszTempChar + pstTextInfo->nSelStart), uiCharCount1 + uiCharCount2 );
*pURLString = pszOutBuf;

void ListItemAdaptSet(void *pvCtx, void *pValueIn, int nLen, void **ppValueOut, int *pnLenOut, PFNVALUEFREE *ppfn)
{
c_RichTextEditSample *pMe = pvCtx;
AECHAR szMarkupText[] = L"\n # \n[blue] (858) 555-1234 [/blue]\n eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%61%62%63%64%65%66%2e%67%68%69%6a%6b%6c%40%6d%6e%6f%70%71%2e%63%6f%6d%22%3e%61%62%63%64%65%66%2e%67%68%69%6a%6b%6c%40%6d%6e%6f%70%71%2e%63%6f%6d%3c%2f%61%3e%27%29%3b')) ";
IRichTextModel *pRichValMdl;
ITextModel *pValMdl;
WidgetPos wpos;
int nErr;
if ( NULL == pValueIn) return;
if(NULL != pMe->m_pRichTextElement)
{
ERR_TRY(IWidget_GetModel(pMe->m_pRichTextElement, AEEIID_ITextModel,(IModel **)&pValMdl));
ERR_TRY( ITextModel_QueryInterface(pValMdl, AEEIID_IRichTextModel, (void **) &pRichValMdl));
IRichTextModel_SetMarkupText(pRichValMdl, szMarkupText, -1);
IRichTextModel_Release(pRichValMdl);
ITextModel_Release(pValMdl);
}
ERR_CATCH:
return;
}
static boolean List_HandleEvent(void *po, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
c_RichTextEditSample * pMe = (c_RichTextEditSample *)po;
boolean bhandled = AEE_EFAILED;
switch (eCode)
{
default:
bhandled = IWidget_HandleEvent(pMe->m_pRichTextElement, eCode, wParam, dwParam);
break; // Event to inform app to start, so start-up code is here:
}
bhandled = HANDLERDESC_CALL(&pMe->hdListWidgetHandler, eCode, wParam, dwParam);
return bhandled;

static boolean ListItem_HandleEvent(void *po, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
c_RichTextEditSample * pMe = (c_RichTextEditSample *)po;
boolean bhandled = AEE_EFAILED;
int pnStartIndex, pnEndIndex, nErr;
char *pszRTContent = NULL;
int iStartIndex = 10, iEndIndex = 10, nListIndex;
switch (eCode)
{
case EVT_POINTER_DOWN:
{
DBGPRINTF_LOW("POINTER DOWN");
}
break;
case EVT_POINTER_UP:
{
DBGPRINTF_LOW("POINTER UP");
}
break;
}
bhandled = HANDLERDESC_CALL(&pMe->hdListItemWidgetHandler, eCode, wParam, dwParam);
if (EVT_POINTER_UP == eCode)
{
ITextModel_GetTextInfo(pMe->m_pTextModel, &pMe->pTextInfo);
DBGPRINTF("Index is %d",pMe->pTextInfo.nSelStart);
DBGPRINTF("Current Char is %c",pMe->pTextInfo.pwText[pMe->pTextInfo.nSelStart]);
IWIDGET_GetFocusIndex(pMe->piwListWidget,&nListIndex);
DBGPRINTF("List Index is %d",nListIndex);
if ('#' == pMe->pTextInfo.pwText[pMe->pTextInfo.nSelStart])
{
ITextModel_SetSel(pMe->m_pTextModel,(pMe->pTextInfo.nSelStart)-1,(pMe->pTextInfo.nSelEndCaret)+2);
}
else
{
ITextModel_SetSel(pMe->m_pTextModel,(pMe->pTextInfo.nSelStart),(pMe->pTextInfo.nSelEndCaret)+1);
}
}
return bhandled;

Not sure if this will help, but as an example of using multiple rich text controls, the c_systemtask app uses these in a grid control. I know this is not a list but it may give you some ideas about getting that working.

Not sure if this will help, but as an example of using multiple rich text controls, the c_systemtask app uses these in a grid control. I know this is not a list but it may give you some ideas about getting that working.

Hi,
I'd like to reproduce the issue you are seeing. Could you supply some sample code in a compilable state? (The code above requires additional #include files and changes to the example applet data structure.)
Thanks,
Sam.

Hi,
I'd like to reproduce the issue you are seeing. Could you supply some sample code in a compilable state? (The code above requires additional #include files and changes to the example applet data structure.)
Thanks,
Sam.

Hi,
I've been informed that the list widget does not generally support the use of touchable widgets as part of its list. The list container should support touchable list items in a future Brew MP release.
Thanks,
Sam.

Hi,
I've been informed that the list widget does not generally support the use of touchable widgets as part of its list. The list container should support touchable list items in a future Brew MP release.
Thanks,
Sam.