新手问个BREW MP中GridWidget的问题

mammoth4 2010-04-14 11:56:45
最近开始学做BREW MP,基础太差,许多东西还是一头雾水。昨天开始写个Grid Widget的例子,想简单的只显示个Static就好,可水平太差不知道怎么写。在Wizard生成的代码的基础上参考了 http://topic.csdn.net/u/20091123/18/3c67c251-79c0-45cf-b799-08ca40a839a5.html 一帖中两位仁兄的代码,现写出如下代码,请各位大哥看看小弟哪里写的有问题,谢谢了。

/*=============================================================================
FILE: GridWidgetSample.c
=============================================================================*/

/*-----------------------------------------------------------------------------
Includes and Variable Definitions
-----------------------------------------------------------------------------*/
#include "AEEModGen.h"
#include "AEEAppGen.h"
#include "AEEShell.h"

#include "GridWidgetSample.bid"
#include "GridWidgetSample_res.h"

/* some property definition, like AEERect, ect. */
#include "AEEWProperties.h"

#include "AEERootContainer.h"
#include "AEECLSID_ROOTCONTAINER.bid"

#include "AEEDisplayCanvas.h"
#include "AEECLSID_DISPLAYCANVAS.bid"

#include "AEEListWidget.h"
#include "AEECLSID_GRIDWIDGET.bid"

#include "AEEStaticWidget.h"
#include "AEECLSID_STATICWIDGET.bid"

#include "AEEIDecorator.h"

#include "AEEIVectorModel.h"
#include "AEECLSID_VECTORMODEL.bid"

#ifndef RELEASEIF
#define RELEASEIF(p) ReleaseIf((IBase**)(void*)&p)

//#define ERR_TRY(x) do { nErr = (x); if (nErr) goto ERR_CATCH; } while(0)

static void ReleaseIf(IBase **ppif) {
if (*ppif) {
IBASE_Release(*ppif);
*ppif = 0;
}
}
#endif

/*-----------------------------------------------------------------------------
Applet Structure
-----------------------------------------------------------------------------*/
typedef struct _GridWidgetSample {
AEEApplet applet;
IDisplay * piDisplay;
IShell * piShell;
AEEDeviceInfo deviceInfo;
// Add your own variables here...
IRootContainer *picRootContainer;
IWidget *piwRootWidget;

} GridWidgetSample;

/*-----------------------------------------------------------------------------
Function Prototypes
-----------------------------------------------------------------------------*/
static boolean GridWidgetSample_HandleEvent(GridWidgetSample* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam);
boolean GridWidgetSample_InitAppData(GridWidgetSample* pMe);
void GridWidgetSample_FreeAppData(GridWidgetSample* pMe);
static void GridWidgetSample_DrawScreen(GridWidgetSample * pMe);

/*-----------------------------------------------------------------------------
Function Definitions
-----------------------------------------------------------------------------*/

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

if( AEECLSID_GRIDWIDGETSAMPLE == ClsId ) {
if( TRUE == AEEApplet_New(sizeof(GridWidgetSample),
ClsId,
piShell,
piModule,
(IApplet**)ppObj,
(AEEHANDLER)GridWidgetSample_HandleEvent,
(PFNFREEAPPDATA)GridWidgetSample_FreeAppData) ) {


if(TRUE == GridWidgetSample_InitAppData((GridWidgetSample*)*ppObj)) {
return AEE_SUCCESS; // Data initialized successfully.
}
else {
IApplet_Release((IApplet*)*ppObj);
return AEE_EFAILED;
}
} // End AEEApplet_New
}
return AEE_EFAILED;
}


/*=============================================================================
FUNCTION: GridWidgetSample_InitAppData
=============================================================================*/
boolean GridWidgetSample_InitAppData(GridWidgetSample * pMe)
{
int nErr;
// 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.
pMe->deviceInfo.wStructSize = sizeof(pMe->deviceInfo);
ISHELL_GetDeviceInfo(pMe->applet.m_pIShell,&pMe->deviceInfo);

// Insert your code here for initializing or allocating resources...
nErr = ISHELL_CreateInstance(pMe->piShell, AEECLSID_ROOTCONTAINER, (void *)(&pMe->picRootContainer));
if (AEE_SUCCESS != nErr) {
return FALSE;
}

nErr = IROOTCONTAINER_QueryInterface(pMe->picRootContainer, AEEIID_WIDGET, (void *)(&pMe->piwRootWidget));
if (AEE_SUCCESS != nErr) {
return FALSE;
}

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


/*=============================================================================
FUNCTION: GridWidgetSample_FreeAppData
=============================================================================*/
void GridWidgetSample_FreeAppData(GridWidgetSample * pMe)
{
// Insert your code here for freeing any resources you have allocated...

// Example to use for releasing each interface:
// if ( NULL != pMe->piMenuCtl ) { // check for NULL first
// IMenuCtl_Release(pMe->piMenuCtl)// release the interface
// pMe->piMenuCtl = NULL; // set to NULL so no problems later
// }
//
}


/*=============================================================================
FUNCTION: GridWidgetSample_HandleEvent
=============================================================================*/
static boolean GridWidgetSample_HandleEvent(GridWidgetSample* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode) {

case EVT_APP_START:
GridWidgetSample_DrawScreen(pMe); // Draw text on display screen.
return TRUE;

case EVT_APP_STOP:
return TRUE;

case EVT_APP_SUSPEND:
return TRUE;

case EVT_APP_RESUME:
GridWidgetSample_DrawScreen(pMe);
return TRUE;

case EVT_APP_MESSAGE:
return TRUE;

case EVT_KEY:
return FALSE;

case EVT_FLIP:
return TRUE;

case EVT_KEYGUARD:
return TRUE;

default:
break;
}
return FALSE; // Event wasn't handled.
}


/*=============================================================================
FUNCTION: GridWidgetSample_DrawScreen
=============================================================================*/
static void GridWidgetSample_DrawScreen(GridWidgetSample * pMe)
{
AEERect rcRoot;
ICanvas *piCanvas;
IWidget *piw, *pisw;
IVectorModel *pivm;
WidgetPos wpos;
WidgetExtent weStatic;
AECHAR pwszText[64] = {0};
int nStrLen = 0;
int nErr;

/* Set Canvas for RootContainer */
SETAEERECT(&(rcRoot), 0, 0, pMe->deviceInfo.cxScreen, pMe->deviceInfo.cyScreen);
nErr = ISHELL_CreateInstance(pMe->piShell, AEECLSID_DISPLAYCANVAS, (void**)&(piCanvas));
if (AEE_SUCCESS != nErr)
{
return;
}

nErr = IDISPLAYCANVAS_SetDisplay((IDisplayCanvas*)(void *)piCanvas, pMe->piDisplay);
if (AEE_SUCCESS != nErr)
{
return;
}

IROOTCONTAINER_SetCanvas(pMe->picRootContainer, piCanvas, &(rcRoot));

RELEASEIF(piCanvas);

nErr = ISHELL_CreateInstance(pMe->piShell, AEECLSID_GRIDWIDGET, (void**)&(piw));
if (AEE_SUCCESS != nErr)
{
return;
}

/* Create the item widget that will be wrapped by the list widget. */
nErr = ISHELL_CreateInstance(pMe->piShell, AEECLSID_STATICWIDGET, (void**)&(pisw));
if (AEE_SUCCESS != nErr)
{
return;
}

/* Identify the value model that is to be associated with this widget. */
nErr = ISHELL_CreateInstance(pMe->piShell, AEECLSID_VECTORMODEL, (void**)&(pivm));
if (AEE_SUCCESS != nErr)
{
return;
}

/* Specify the text to be displayed within the static widget */
nStrLen = ISHELL_LoadResString(pMe->piShell,
GRIDWIDGETSAMPLE_RES_FILE,
IDS_STRING_1001, pwszText, sizeof(pwszText));

if (pwszText)
{
IValueModel *piValueModel = 0;
if (AEE_SUCCESS == IWidget_GetModel(pisw, AEEIID_VALUEMODEL, (IModel **)(void**) &(piValueModel)))
{
IVALUEMODEL_SetText(piValueModel, pwszText, -1);
IValueModel_Release(piValueModel);
}
}

/* Attach the appropriate model to the list. */
nErr = IWidget_SetModel(piw, IVectorModel_to_IModel(pivm));
if (AEE_SUCCESS != nErr)
{
return;
}

/* Wrap the list widget around the item widget, use staticWidget as 'item' widget. */
IDecorator_SetWidget((IDecorator *)(void*) piw, pisw);

IWidget_SetRows(piw, 2);
IWidget_SetCols(piw, 3);

IWidget_GetPreferredExtent(pisw, &weStatic);

/* Set the width and height of the list widget. */
IWidget_SetItemWidth(piw, weStatic.width);
IWidget_SetItemHeight(piw, weStatic.height);

weStatic.width = 200;
weStatic.height = 240;
IWidget_SetExtent(piw, &weStatic);

IWidget_SetBGColor(pisw, MAKE_RGB(0,0,255));

wpos.x = 0;
wpos.y = 0;
wpos.bVisible = TRUE;

IROOTCONTAINER_Insert( pMe->picRootContainer, piw, WIDGET_ZNORMAL, &wpos );

RELEASEIF(piw);
RELEASEIF(pisw);
RELEASEIF(pivm);

}
...全文
794 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
twoconk 2010-04-20
  • 打赏
  • 举报
回复
两点哦:
1. 2行3列的GridWidget没有任何内容哦,因为你的pivm Vectormodel里面没有任何数据
2. 就是楼上说的GridWidget每一个item里面的STATICWIDGET没有数据, 解决方法是给ValueModel设置一个Adapte

最好用bmp的例子先看明白哦, 这个理解还是有点复杂的~
mammoth4 2010-04-20
  • 打赏
  • 举报
回复
谢谢楼上两位,这两天在别人指点下已经写出grid slider progress list tab等几个widget了,上来把帖结了,以后有问题还会继续来讨教的,谢谢。
FLYUP_CHEN 2010-04-19
  • 打赏
  • 举报
回复
我大概看了一下你的代码,你的widget应该是已经画上去了,但是文字应该没有显示。不知道是不是这样,文字显示是需要你要给static widget做一个set的动作的,添加一个ValueModel的Listener当值发生改变的时候给staitc widget设置一下文字。
mammoth4 2010-04-16
  • 打赏
  • 举报
回复
呃。是不是我这问题太幼稚了?没人理哦~
mammoth4 2010-04-14
  • 打赏
  • 举报
回复
加了注释超过1万字符了,就把注释基本都去了。请各位大哥教教小弟,谢谢了。

962

社区成员

发帖
与我相关
我的任务
社区描述
为开发者提供高通丰富的解决方案及全面技术下载内容。本版以AI人工智能、WoS 骁龙本、XR、IoT 物联网、Auto 汽车、生成式AI等核心板块组成,为开发者提供一个便捷及高效的学习交流平台。
人工智能物联网机器学习 企业社区 北京·东城区
社区管理员
  • csdnsqst0050
  • chipseeker
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧