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

Developer

Forums

Forums:

Hi,     I have created slider widget, but i am unable handle events. if i click on slider first time its going to callback function.next time onwords it doesnt generate any events even if i moved the slider.please find the below code and help me static void Create_Slider_Widget(Sample1 * pMe){    IWidget *pIWidget;     uint16 Result1;    IWidget *SliderContainer = NULL;    IXYContainer *XYcontainerWidget = NULL;    IDisplayCanvas *pCanvas = NULL;    WidgetPos ppos;    WidgetExtent pWExtent;    WidgetExtent WEI;    WidgetPos pposI;    int Result;    AEERect displayRect;    WidgetExtent WE;    WidgetPos WPos;    Result = IWidget_SetBGColor(pMe->pRootContWgt,MAKE_RGB(0,0,255));    Result = ISHELL_CreateInstance(pMe->piShell, AEECLSID_DisplayCanvas, (void**)&pCanvas);    IDisplayCanvas_SetDisplay(pCanvas,pMe->piDisplay);    // Set the canvas size to equal the device screen dimensions    SETAEERECT(&displayRect, 0, 0, (int16)pMe->deviceInfo.cxScreen, (int16)pMe->deviceInfo.cyScreen);    IRootContainer_SetCanvas(pMe->pRootCont, (ICanvas*)(void*)pCanvas, &displayRect);    // Create SliderWidget Instance.     Result = ISHELL_CreateInstance(pMe->piShell,AEECLSID_SliderWidget, (void**)&pMe->pISliderWidget);    // Result = ISHELL_CreateInstance(pMe->piShell, AEECLSID_SliderTC, (void**)&pMe->pISliderWidgetTC);    // Result = ISHELL_CreateInstance(pMe->piShell, AEECLSID_OEMSliderTC, (void**)&pMe->pISliderWidget);   Result = IWidget_GetSliderMaxPos(pMe->pISliderWidget, &Result1);     // set properties    Result = IWidget_GetLayoutStyle(pMe->pISliderWidget,&Result);    Result =IWidget_SetLayoutStyle(pMe->pISliderWidget,LAYOUT_HORZ);     Result = IWidget_SetPadding(pMe->pISliderWidget,2);    Result = IWidget_SetBorderWidth(pMe->pISliderWidget,2);    Result = IWidget_SetBorderColor(pMe->pISliderWidget,MAKE_RGB(255,0,0));    Result = IWidget_SetBGColor(pMe->pISliderWidget,MAKE_RGB(255,255,0));    Result = IWidget_SetSliderHandleBorderColor(pMe->pISliderWidget,MAKE_RGB(0,0,255));    Result = IWidget_SetSliderMaxPos(pMe->pISliderWidget,5);    Result = IWidget_SetActiveBGColor(pMe->pISliderWidget,MAKE_RGB(255,0,0));    Result = IWidget_SetActiveBorderColor(pMe->pISliderWidget,MAKE_RGB(255,0,0));    //IWidget_GetSliderHandleWidget();    //IWidget_SetSliderHandleWidget();      IWidget_GetPreferredExtent(pMe->pISliderWidget, &WE);      WE.height = 20;    WE.width = 100;   // set the extent of widget     IWidget_SetExtent(pMe->pISliderWidget,&WE);     WPos.x = 50;    WPos.y = 200;     WPos.bVisible = TRUE;     Result = IRootContainer_Insert(pMe->pRootCont,pMe->pISliderWidget,WIDGET_ZTOPMOST,&WPos);         {               IModel *pViewModel;               IWidget_GetViewModel(pMe->pISliderWidget,&pViewModel);               IModel_AddListenerEx(pViewModel, &pMe->hdSliderListen, (PFNLISTENER)c_SystemTaskApp_SliderHandler,(void *)pMe);               IQI_RELEASEIF(pViewModel);       }          (void)IDisplayCanvas_Release(pCanvas);     //IWidget_Release(pISliderWidget);    }Thanks,Hanamant

I tried code below and it worked.
static boolean sliderapp_HandleEvent(sliderapp* pMe,
AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
...............
// pass any unhandled events to the RC
if(pMe->piwRoot)
return IWidget_HandleEvent(pMe->piwRoot, eCode, wParam, dwParam);

static void sliderapp_SliderListener(sliderapp *me, ModelEvent *pEvent)
{

static int sliderapp_CreateSliderWidget(sliderapp *me)
{
WidgetExtent we;
int nErr = 0;
IModel *pivm = 0;

ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_SliderWidget, (void**)&me->piwSliderHorz) );

ERR_TRY( IWidget_SetLayoutStyle(me->piwSliderHorz, AEEWIDGET_LAYOUT_HORZ));
IWidget_SetSliderMaxPos(me->piwSliderHorz, 50);
IWidget_GetPreferredExtent(me->piwSliderHorz, &we);
IWidget_SetExtent(me->piwSliderHorz, &we);

ERR_TRY( IWidget_GetModel(me->piwSliderHorz, AEEIID_IValueModel, &pivm) );

ERR_TRY( IModel_AddListenerEx(pivm, &me->mlSlider, (PFNLISTENER)sliderapp_SliderListener, me) );

ERR_CATCH:
return nErr;

static void sliderapp_DrawScreen(sliderapp * me)
{
AEEResult nErr;
AEERect rect;
IDisplayCanvas *piDisplayCanvas = NULL;
ICanvas *piCanvas = NULL;
// Get the device information for this handset.
// Reference all the data by looking at the me->DeviceInfo structure
// Check the API reference guide for all the handy device info you can get
me->deviceInfo.wStructSize = sizeof(me->deviceInfo);
ISHELL_GetDeviceInfo(me->applet.m_pIShell,&me->deviceInfo);
me->piDisplay = me->applet.m_pIDisplay;
me->piShell = me->applet.m_pIShell;

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);

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

{
WidgetPos wp;
WidgetExtent we = {0};

wp.bVisible = TRUE;

ERR_TRY( sliderapp_CreateSliderWidget(me) );

wp.x = 10;
wp.y = 50;
ERR_TRY( IRootContainer_Insert(me->picRoot, me->piwSliderHorz, WIDGET_ZTOPMOST, &wp) );

}

ERR_CATCH:
RELEASEIF(piCanvas);
RELEASEIF(piDisplayCanvas);

I tried code below and it worked.
static boolean sliderapp_HandleEvent(sliderapp* pMe,
AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
...............
// pass any unhandled events to the RC
if(pMe->piwRoot)
return IWidget_HandleEvent(pMe->piwRoot, eCode, wParam, dwParam);

static void sliderapp_SliderListener(sliderapp *me, ModelEvent *pEvent)
{

static int sliderapp_CreateSliderWidget(sliderapp *me)
{
WidgetExtent we;
int nErr = 0;
IModel *pivm = 0;

ERR_TRY( ISHELL_CreateInstance(me->piShell, AEECLSID_SliderWidget, (void**)&me->piwSliderHorz) );

ERR_TRY( IWidget_SetLayoutStyle(me->piwSliderHorz, AEEWIDGET_LAYOUT_HORZ));
IWidget_SetSliderMaxPos(me->piwSliderHorz, 50);
IWidget_GetPreferredExtent(me->piwSliderHorz, &we);
IWidget_SetExtent(me->piwSliderHorz, &we);

ERR_TRY( IWidget_GetModel(me->piwSliderHorz, AEEIID_IValueModel, &pivm) );

ERR_TRY( IModel_AddListenerEx(pivm, &me->mlSlider, (PFNLISTENER)sliderapp_SliderListener, me) );

ERR_CATCH:
return nErr;

static void sliderapp_DrawScreen(sliderapp * me)
{
AEEResult nErr;
AEERect rect;
IDisplayCanvas *piDisplayCanvas = NULL;
ICanvas *piCanvas = NULL;
// Get the device information for this handset.
// Reference all the data by looking at the me->DeviceInfo structure
// Check the API reference guide for all the handy device info you can get
me->deviceInfo.wStructSize = sizeof(me->deviceInfo);
ISHELL_GetDeviceInfo(me->applet.m_pIShell,&me->deviceInfo);
me->piDisplay = me->applet.m_pIDisplay;
me->piShell = me->applet.m_pIShell;

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);

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

{
WidgetPos wp;
WidgetExtent we = {0};

wp.bVisible = TRUE;

ERR_TRY( sliderapp_CreateSliderWidget(me) );

wp.x = 10;
wp.y = 50;
ERR_TRY( IRootContainer_Insert(me->picRoot, me->piwSliderHorz, WIDGET_ZTOPMOST, &wp) );

}

ERR_CATCH:
RELEASEIF(piCanvas);
RELEASEIF(piDisplayCanvas);