Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

HI all,

 

In my sample html application, it contains many url's and focus is also changning from one url to another. what i want is, if user selects the highligted URL then i have to get that URL text and do the next process, so the problem I'm facing is how to get the selected URL text, Please provide any solution or snippet .

 

-hanu

You need to install view model listener on the HTML widget to listen for model events like focus change, selection , loading etc. When user selects URL, app gets EVT_HVM_JUMP event in registed view model listener. You can get the URL selected using ((HTMLViewEvent*)pEv)->u.jump.pszURL. pEv is ModelEvent pointer. Sample code snippet below:
//HTML widget variables (part of applet structure)
IWidget *piwHTML;
IDocModel *pimDocHtml;
IHTMLViewModel *pimViewHtml;
ModelListener mlHtmlDoc, mlHtmlView;
IWeb *piWeb;

//HTML widget local variables
int bWrote;
IModel *pimModelHtml;
ISource *piSource = NULL;
IFile * piFile = NULL;
IFileMgr *piFileM; // handle to file mgr
ISourceUtil *piSourceUtil; // handle to source util

//Create and configure HTML widget
ret = ISHELL_CreateInstance(pMe->piShell, AEECLSID_HTMLWidget, (void**)&pMe->piwHTML);
if(ret != SUCCESS)
{
DBGPRINTF("piwHTML failed[%d]", ret);
return;
}
ret = ISHELL_CreateInstance(pMe->piShell, AEECLSID_WEB, (void**)&(pMe->piWeb));
if(ret != SUCCESS)
{
DBGPRINTF("piWeb failed[%d]", ret);
return;
}
IWidget_SetBGColor(pMe->piwHTML, MAKE_RGBA(198,198,198,255));

pWExtent.width = pMe->deviceInfo.cxScreen;
pWExtent.height = pMe->deviceInfo.cyScreen;
IWidget_SetExtent(pMe->piwHTML,&pWExtent);
IWIDGET_SetIWeb(pMe->piwHTML, pMe->piWeb);

IWidget_GetModel(pMe->piwHTML, AEEIID_IDocModel, (IModel**)&pMe->pimDocHtml);

IWidget_GetViewModel(pMe->piwHTML, (IModel**)&pimModelHtml);
IModel_QueryInterface(pimModelHtml, AEEIID_IHTMLViewModel, (void**)&pMe->pimViewHtml);
if(ret != SUCCESS)
{
DBGPRINTF("pimViewHtml failed[%d]", ret);
return;
}
// Add Listeners for HTML Widget
LISTENER_SetListenerInfo(&pMe->mlHtmlDoc, c_widgetsapp_htmldoclistener, pMe);
LISTENER_SetListenerInfo(&pMe->mlHtmlView, c_widgetsapp_htmlviewlistener, pMe);
IDocModel_AddListener(pMe->pimDocHtml, &pMe->mlHtmlDoc);
IHTMLViewModel_AddListener(pMe->pimViewHtml,&pMe->mlHtmlView);

// insert widget into root container
ppos.bVisible = TRUE;
ppos.x = (pMe->deviceInfo.cxScreen - pWExtent.width)/2;
ppos.y = 10;
IRootContainer_Insert(pMe->picRootText, pMe->piwHTML, WIDGET_ZNORMAL, &ppos);
IWidget_MoveFocus(pMe->piwRootText, CAST(IWidget*, pMe->piwHTML));

// get handle to file manager
ret = ISHELL_CreateInstance(pMe->piShell, AEECLSID_FILEMGR, (void**)&(piFileM));
if(ret != SUCCESS)
{
DBGPRINTF("piFileM failed[%d]", ret);
return;
}
// get handle to source util
ret = ISHELL_CreateInstance(pMe->piShell, AEECLSID_SOURCEUTIL, (void **)&(piSourceUtil));
if(ret != SUCCESS)
{
DBGPRINTF("piSourceUtil failed[%d]", ret);
return;
}
piFile = IFILEMGR_OpenFile(piFileM, "hsrc/index.htm",_OFM_READ);//index.htm is a html file
(void)IFILEMGR_GetLastError(piFileM);
(void)ISOURCEUTIL_SourceFromAStream(piSourceUtil, (IAStream *)(void *)piFile, &piSource);

if (NULL != piFile)
{
(void)IDocModel_LoadSource(pMe->pimDocHtml, piSource);
}

// VIEW MODEL LISTENERS
void c_widgetsapp_htmlviewlistener(c_widgetsapp* me, ModelEvent *pEv)
{

// base document (objects/images pending)
if (pEv->evCode == EVT_HVM_DONE) {
DBGPRINTF("EVT_HVM_DONE");
}
// first visible page (including objects/images) - this page can be a part of a big html page
if (pEv->evCode == EVT_HVM_PAGEDONE) {
DBGPRINTF("EVT_HVM_PAGEDONE");
}
// document load complete (including objects/images)
if (pEv->evCode == EVT_HVM_CONTENTDONE) {
DBGPRINTF("EVT_HVM_CONTENTDONE");
}
// user selected jump
if (pEv->evCode == EVT_HVM_JUMP) {
DBGPRINTF("EVT_HVM_JUMP %s", ((HTMLViewEvent*)pEv)->u.jump.pszURL);
}
// user submitted form
if (pEv->evCode == EVT_HVM_SUBMIT) {
DBGPRINTF("EVT_HVM_SUBMIT");
}
// focus has changed
if (pEv->evCode == EVT_HVM_FOCUS) {
DBGPRINTF("EVT_HVM_FOCUS");
}
return;

// DOCUMENT MODEL LISTENERS
void c_widgetsapp_htmldoclistener(c_widgetsapp* me, ModelEvent *pEv)
{
(void)me;
// document has been reset
if (pEv->evCode == EVT_HDM_RESET) {

}
// document load has been stopped
if (pEv->evCode == EVT_HDM_STOP) {

}
return;

You need to install view model listener on the HTML widget to listen for model events like focus change, selection , loading etc. When user selects URL, app gets EVT_HVM_JUMP event in registed view model listener. You can get the URL selected using ((HTMLViewEvent*)pEv)->u.jump.pszURL. pEv is ModelEvent pointer. Sample code snippet below:
//HTML widget variables (part of applet structure)
IWidget *piwHTML;
IDocModel *pimDocHtml;
IHTMLViewModel *pimViewHtml;
ModelListener mlHtmlDoc, mlHtmlView;
IWeb *piWeb;

//HTML widget local variables
int bWrote;
IModel *pimModelHtml;
ISource *piSource = NULL;
IFile * piFile = NULL;
IFileMgr *piFileM; // handle to file mgr
ISourceUtil *piSourceUtil; // handle to source util

//Create and configure HTML widget
ret = ISHELL_CreateInstance(pMe->piShell, AEECLSID_HTMLWidget, (void**)&pMe->piwHTML);
if(ret != SUCCESS)
{
DBGPRINTF("piwHTML failed[%d]", ret);
return;
}
ret = ISHELL_CreateInstance(pMe->piShell, AEECLSID_WEB, (void**)&(pMe->piWeb));
if(ret != SUCCESS)
{
DBGPRINTF("piWeb failed[%d]", ret);
return;
}
IWidget_SetBGColor(pMe->piwHTML, MAKE_RGBA(198,198,198,255));

pWExtent.width = pMe->deviceInfo.cxScreen;
pWExtent.height = pMe->deviceInfo.cyScreen;
IWidget_SetExtent(pMe->piwHTML,&pWExtent);
IWIDGET_SetIWeb(pMe->piwHTML, pMe->piWeb);

IWidget_GetModel(pMe->piwHTML, AEEIID_IDocModel, (IModel**)&pMe->pimDocHtml);

IWidget_GetViewModel(pMe->piwHTML, (IModel**)&pimModelHtml);
IModel_QueryInterface(pimModelHtml, AEEIID_IHTMLViewModel, (void**)&pMe->pimViewHtml);
if(ret != SUCCESS)
{
DBGPRINTF("pimViewHtml failed[%d]", ret);
return;
}
// Add Listeners for HTML Widget
LISTENER_SetListenerInfo(&pMe->mlHtmlDoc, c_widgetsapp_htmldoclistener, pMe);
LISTENER_SetListenerInfo(&pMe->mlHtmlView, c_widgetsapp_htmlviewlistener, pMe);
IDocModel_AddListener(pMe->pimDocHtml, &pMe->mlHtmlDoc);
IHTMLViewModel_AddListener(pMe->pimViewHtml,&pMe->mlHtmlView);

// insert widget into root container
ppos.bVisible = TRUE;
ppos.x = (pMe->deviceInfo.cxScreen - pWExtent.width)/2;
ppos.y = 10;
IRootContainer_Insert(pMe->picRootText, pMe->piwHTML, WIDGET_ZNORMAL, &ppos);
IWidget_MoveFocus(pMe->piwRootText, CAST(IWidget*, pMe->piwHTML));

// get handle to file manager
ret = ISHELL_CreateInstance(pMe->piShell, AEECLSID_FILEMGR, (void**)&(piFileM));
if(ret != SUCCESS)
{
DBGPRINTF("piFileM failed[%d]", ret);
return;
}
// get handle to source util
ret = ISHELL_CreateInstance(pMe->piShell, AEECLSID_SOURCEUTIL, (void **)&(piSourceUtil));
if(ret != SUCCESS)
{
DBGPRINTF("piSourceUtil failed[%d]", ret);
return;
}
piFile = IFILEMGR_OpenFile(piFileM, "hsrc/index.htm",_OFM_READ);//index.htm is a html file
(void)IFILEMGR_GetLastError(piFileM);
(void)ISOURCEUTIL_SourceFromAStream(piSourceUtil, (IAStream *)(void *)piFile, &piSource);

if (NULL != piFile)
{
(void)IDocModel_LoadSource(pMe->pimDocHtml, piSource);
}

// VIEW MODEL LISTENERS
void c_widgetsapp_htmlviewlistener(c_widgetsapp* me, ModelEvent *pEv)
{

// base document (objects/images pending)
if (pEv->evCode == EVT_HVM_DONE) {
DBGPRINTF("EVT_HVM_DONE");
}
// first visible page (including objects/images) - this page can be a part of a big html page
if (pEv->evCode == EVT_HVM_PAGEDONE) {
DBGPRINTF("EVT_HVM_PAGEDONE");
}
// document load complete (including objects/images)
if (pEv->evCode == EVT_HVM_CONTENTDONE) {
DBGPRINTF("EVT_HVM_CONTENTDONE");
}
// user selected jump
if (pEv->evCode == EVT_HVM_JUMP) {
DBGPRINTF("EVT_HVM_JUMP %s", ((HTMLViewEvent*)pEv)->u.jump.pszURL);
}
// user submitted form
if (pEv->evCode == EVT_HVM_SUBMIT) {
DBGPRINTF("EVT_HVM_SUBMIT");
}
// focus has changed
if (pEv->evCode == EVT_HVM_FOCUS) {
DBGPRINTF("EVT_HVM_FOCUS");
}
return;

// DOCUMENT MODEL LISTENERS
void c_widgetsapp_htmldoclistener(c_widgetsapp* me, ModelEvent *pEv)
{
(void)me;
// document has been reset
if (pEv->evCode == EVT_HDM_RESET) {

}
// document load has been stopped
if (pEv->evCode == EVT_HDM_STOP) {

}
return;