20110520 Brew之TabWidget实例

本文档详细介绍了如何在Brew平台上使用TabWidget进行应用开发,包括创建TabApp工程、编写Includer.h和Helper.h文件,以及BaseWin类的实现。主要涉及了Brew中各种Widget类的引用和内存管理方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Brew之TabWidget实例

 

一、创建TabApp工程,做如下准备工作

 

      1、在工程文件下添加TabAp.h、TabApp.cpp、BaseWin.h、BaseWin.cpp、Includer.h、Helper.h这样几个文件

      2、打开工程,将上面的这些文件添加到工程,然后删除原有的TabAPP.c

      3、文件将forms,widgets,widgettc这样一些必要的文件夹复制到.mif同目录的文件夹下

 

二、编写代码

 

      1、编写Includer.h文件

 

#ifndef INCLUDER_BUIW_H_
#define INCLUDER_BUIW_H_

extern "C"
{
//Form
 #include "AEEForm.h"
 #include "AEECLSID_FORM.bid"
//RootForm
 #include "AEERootForm.h"
 #include "AEECLSID_ROOTFORM.bid"
//Popup
 #include "AEEPopup.h"
 #include "AEECLSID_POPUPFORM.bid"  /*Identifies the class ID of the popup form*/
 #include "AEECLSID_POPUPMENUFORM.bid"  /*Identifies the class ID of the popup menu form*/
 #include "AEECLSID_POPUPMENUFORM_SCROLL.bid" /*Identifies the class ID of the popup menu form with scrollbar*/
//Dialog
 #include "AEEDialog.h"
 #include "AEECLSID_DIALOGFORM.bid"  /*Identifies the class ID of the dialog form*/
 #include "AEECLSID_PROGRESSDIALOG.bid"  /*Identifies the class ID of the progress dialog*/
 #include "AEECLSID_INFODIALOG.bid"  /*Identifies the class ID of the info message dialog*/
 #include "AEECLSID_ERRORDIALOG.bid"  /*Identifies the class ID of the error message dialog*/
 #include "AEECLSID_WARNDIALOG.bid"  /*Identifies the class ID of the warning message dialog*/
//listForm
 #include "AEEListForm.h"
 #include "AEECLSID_LISTFORM.bid"  /*Identifies the class ID of the list form*/
 #include "AEECLSID_LISTFORM_SCROLL.bid"  /*Identifies the class ID of the scrollbar list form*/
//Bitmap Widget
 #include "AEEBitmapWidget.h"
 #include "AEECLSID_BITMAPWIDGET.bid"  /*Identifies the class ID of the bitmap widget*/
//Blend Widget
 #include "AEEBlendWidget.h"
 #include "AEECLSID_BLENDWIDGET.bid"  /*Identifies the class ID of the blend widget*/
//Border Widget
 #include "AEEBorderWidget.h"
 #include "AEECLSID_BORDERWIDGET.bid"  /*Identifies the class ID of the border widget*/
//button Widget
 #include "AEEButtonWidget.h"
 #include "AEECLSID_BUTTONWIDGET.bid"  /*Identifies the class ID of the button widget*/
//Canvas
 #include "AEECanvas.h"
 #include "AEECLSID_CANVAS.bid"   /*Class ID for an instance of an ICanvas object*/
//Card Container
 #include "AEECardContainer.h"
 #include "AEECLSID_CARDCONTAINER.bid"  /*Identifies the class ID of the card container*/
//Caret Widget
 #include "AEECaretWidget.h"
 #include "AEECLSID_CARETWIDGET.bid"  /*Identifies the class ID of the caret widget*/
//Check Widget
 #include "AEECheckWidget.h"
 #include "AEECLSID_CHECKWIDGET.bid"  /*Identifies the class ID of the checkbox widget*/
 #include "AEECLSID_RADIOWIDGET.bid"  /*Identifies the class ID of the radio button widget*/
//Constraint Container
 #include "AEEConstraintContainer.h"
 #include "AEECLSID_CONSTRAINTCONTAINER.bid" /*Identifies the class ID of the constraint container*/
//Cursor Widget
 #include "AEECursorWidget.h"
 #include "AEECLSID_CURSORWIDGET.bid"  /*Identifies the class ID of the cursor widget*/
//DateTime Widget
 #include "AEEDateTimeWidget.h"
 #include "AEECLSID_JULIANDATEWIDGET.bid" /* Identifies the class ID of the julian date widget*/
 #include "AEECLSID_JULIANTIMEWIDGET.bid" /* Identifies the class ID of the julian time widget*/
 #include "AEECLSID_DATEWIDGET.bid"  /* Identifies the class ID of the date widget (DEPRECATED)*/
 #include "AEECLSID_TIMEWIDGET.bid"  /* Identifies the class ID of the time widget (DEPRECATED)*/
//Display Canvas
 #include "AEEDisplayCanvas.h"
 #include "AEECLSID_DISPLAYCANVAS.bid"  /*Class ID for an instance of an ICanvas object*/
//DrawDecorator Widget
 #include "AEEDrawDecoratorWidget.h"
 #include "AEECLSID_DRAWDECORATORWIDGET.bid" /*Identifies the class ID of the draw decorator widget*/
//FontMap Model
 #include "AEEFontMapModel.h"
 #include "AEECLSID_FONTMAPMODEL.bid"  /*Identifies the class ID of the font map model*/
//Grid Container
 #include "AEEGridContainer.h"
 #include "AEECLSID_GRIDCONTAINER.bid"  /*Identifies the class ID of the grid container*/
//ImageStatic Widget
 #include "AEEImageStaticWidget.h"
 #include "AEECLSID_IMAGESTATICWIDGET.bid" /*Identifies the class ID of the image static widget*/
//Image Widget
 #include "AEEImageWidget.h"
 #include "AEECLSID_IMAGEWIDGET.bid"  /*Identifies the class ID of the image widget*/
//List Widget
 #include "AEEListWidget.h"
 #include "AEECLSID_LISTWIDGET.bid"  /*Identifies the class ID of the list widget*/
 #include "AEECLSID_PICKWIDGET.bid"  /*Identifies the class ID of the pick widget*/
 #include "AEECLSID_GRIDWIDGET.bid"  /*Identifies the class ID of the grid widget*/
//Locale
 #include "AEELocale.h"
 #include "AEECLSID_CURRENTLOCALE.bid"  /*Identifies the ID of the current system locale class.*/
//Menu Model
 #include "AEEMenuModel.h"
 #include "AEECLSID_MENUMODEL.bid"  /*Identifies the class ID of the menu model*/
//Progress Widget
 #include "AEEProgressWidget.h"
 #include "AEECLSID_PROGRESSWIDGET.bid"  /*Identifies the class ID of the progress widget*/
//Prop Container
 #include "AEEPropContainer.h"
 #include "AEECLSID_PROPCONTAINER.bid"  /*Identifies the class ID of the prop container*/
//ResFile
 #include "AEEResFile.h"
 #include "AEECLSID_RESFILE.bid"   /*Identifies the class ID of the ResFile */
//Root Container
 #include "AEERootContainer.h"
 #include "AEECLSID_ROOTCONTAINER.bid"   /*Identifies the class ID of the root container*/
//Scroll Widget
 #include "AEEScrollWidget.h"
 #include "AEECLSID_SCROLLBARWIDGET.bid"  /*Identifies the class ID of the scrollbar widget*/
 #include "AEECLSID_SCROLLINDICATORWIDGET.bid" /*Identifies the class ID of the scroll indicator widget*/
//Slider Widget
 #include "AEESliderWidget.h"
 #include "AEECLSID_SLIDERWIDGET.bid"  /*Identifies the class ID of the slider widget*/
//Softkey Widget
 #include "AEESoftkeyWidget.h"
 #include "AEECLSID_SOFTKEYWIDGET.bid"  /*Identifies the class ID of the softkey widget*/
//Static Widget
 #include "AEEStaticWidget.h"
 #include "AEECLSID_STATICWIDGET.bid"  /*Identifies the class ID of the static widget*/
//Tab Widget
 #include "AEETabWidget.h"
 #include "AEECLSID_TABWIDGET.bid"  /*Identifies the class ID of the tab widget*/
//Text Widget
 #include "AEETextWidget.h"
 #include "AEECLSID_TEXTWIDGET.bid"  /*Identifies the class ID of the softkey widget*/
//Title Widget
 #include "AEETitleWidget.h"
 #include "AEECLSID_TITLEWIDGET.bid"  /*Identifies the class ID of the title widget*/
//Transition
 #include "AEETransition.h"
 #include "AEECLSID_FADER.bid"   /*Identifies the class ID of the popup form*/
 #include "AEECLSID_MOVER.bid"   /*Identifies the class ID of the popup menu form*/
//Vector Model
 #include "AEEVectorModel.h"
 #include "AEECLSID_VECTORMODEL.bid"  /*Identifies the class ID of the vector model*/
//Viewport Widget
 #include "AEEViewportWidget.h"
 #include "AEECLSID_VIEWPORTWIDGET.bid"   /*Identifies the class ID of the viewport widget*/
//WModel
 #include "AEEWModel.h"
 #include "AEECLSID_VALUEMODEL.bid"  /*Identifies the class ID of the value model*/
 #include "AEECLSID_INTERFACEMODEL.bid"  /*Identifies the class ID of the interface model*/     
//XYContainer
 #include "AEEXYContainer.h"
 #include "AEECLSID_XYCONTAINER.bid"  /*Identifies the class ID of the XY container*/
//Array Model
 #include "AEEArrayModel.h"
 #include "AEECLSID_ARRAYMODEL.bid"  /*Identifies the class ID of the array model*/
//IBASE_AddRef
 #ifndef ADDREFIF
 #define ADDREFIF(p) if(p){IBASE_AddRef((IBase*)p);p=NULL;}
 #endif
//IBASE_Release
 #ifndef RELEASEIF
 #define RELEASEIF(p) if(p){IBASE_Release((IBase*)p);p=NULL;}
 #endif
}

#endif

 

2、编写Helper.h文件

 

#ifndef _HELPER_H_
#define _HELPER_H_

extern "C"
{
#include "aeestdlib.h"
}

//内存的分配和释放
inline  void*   operator new        (size_t,void* a0)   throw() {return(a0);}
inline  void*   operator new []     (size_t,void* a0)   throw() {return(a0);}
inline  void*   operator new        (size_t r0)         throw() {return(MALLOC(r0));}
inline  void*   operator new []     (size_t r0)         throw() {return(MALLOC(r0));}
inline  void    operator delete     (void*,void*)               {return;}
inline  void    operator delete []  (void*,void*)               {return;}
inline  void    operator delete     (void* a0)                  {FREE(a0);return;}
inline  void    operator delete []  (void* a0)                  {FREE(a0);return;}


//指针重释
#ifndef AEE_SIMULATOR
 template
 inline  T       reinterpret_brew    (const void* a0)            {return(T(a0));}
 template
 inline  T       static_brew         (const void* a0)            {return(T(a0));}
 template
 inline  T       dynamic_brew        (const void* a0)            {return(T(a0));}
 template
 inline  T       const_brew          (const void* a0)            {return(T(a0));}
#else
 #define         reinterpret_brew    reinterpret_cast
 #define         static_brew         static_cast
 #define         dynamic_brew        dynamic_cast
 #define         const_brew          const_cast
#endif


#define CREATEME( type ) /
 {      /
  void* p = MALLOC( sizeof(type) ); /
  if( p )     /
  {      /
   new(p)type();  /
   return (type*)p; /
  }      /
  return 0;    /
 }

#define FREEME( type, p ) /
 {     /
  if( p )   /
  {    /
   p->~type(); /
   FREE(p); /
  }    /
 }

#define _T(x) ((const AECHAR *)L##x)

#define ERR_TRY(x) { if( (nErr=x) != SUCCESS ) goto ERR_CATCH; }

#define DEFINE_CREATOR(T) /
  static T* CreateInstance() /
  { /
   CREATEME(T); /
  }

#endif //_HELPER_H_

 

3、编写BaseWin.h文件

 

#ifndef BASEWIN_H_
#define BASEWIN_H_

#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "AEEFile.h"   // File interface definitions
#include "AEEDB.h"    // Database interface definitions
#include "AEENet.h"    // Socket interface definitions
#include "AEESound.h"   // Sound Interface definitions
#include "AEETapi.h"   // TAPI Interface definitions

#include "TabApp.bid"
#include "TabApp.brh"
#include "Includer.h"
#include "Helper.h"

class BaseWin
{
public:
 BaseWin(IShell* pShell,IRootForm* pRootForm);
 virtual ~BaseWin();
public:
 static boolean HandleEvent(BaseWin* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam);
 boolean InitAppData();
 int ShowForm(IRootForm* pRootForm);
 static void FreeAppData(BaseWin* pMe);
 static void FreeVectorModel(void* pData);
public:
 IShell*   m_pShell;
 AEEDeviceInfo m_DeviceInfo;
 HandlerDesc  m_HandlerDesc;
 IForm*   m_pForm;
 IRootForm*  m_pRootForm;
 IWidget*  m_pTabWidget;
 IVectorModel* m_pVectorModel;
 ICardContainer* m_pCardContainer;
 ImageStaticInfo m_ImageStaticInfo[10];
};

#endif BASEWIN_H_

 

4、编写BaseWin.cpp

 

#include "BaseWin.h"

BaseWin::BaseWin(IShell* pShell,IRootForm* pRootForm):m_pForm(NULL),
m_pTabWidget(NULL),
m_pVectorModel(NULL),
m_pCardContainer(NULL)
{
 m_pShell = pShell;
 m_pRootForm = pRootForm;

 ISHELL_CreateInstance(m_pShell,AEECLSID_FORM,(void**)&m_pForm);
 ISHELL_CreateInstance(m_pShell,AEECLSID_TABWIDGET,(void**)&m_pTabWidget);
 ISHELL_CreateInstance(m_pShell,AEECLSID_VECTORMODEL,(void**)&m_pVectorModel);
 ISHELL_CreateInstance(m_pShell,AEECLSID_CARDCONTAINER,(void**)&m_pCardContainer);
 HANDLERDESC_Init( &m_HandlerDesc,(PFNHANDLER)BaseWin::HandleEvent, this, (PFNHANDLER)BaseWin::FreeAppData );
 IFORM_SetHandler(m_pForm, &m_HandlerDesc );
}

BaseWin::~BaseWin()
{
 
}

boolean BaseWin::HandleEvent(BaseWin* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
 if (eCode == EVT_KEY)
 {
  if (wParam == AVK_CLR)
  {
   return SUCCESS;
  }
 }
 return HANDLERDESC_Call( &pMe->m_HandlerDesc, eCode, wParam, dwParam );
}

boolean BaseWin::InitAppData()
{
 IImage*  pImageTitle = NULL; 
 AECHAR*  pStaticText =NULL;
 IWidget* pCardContainerWig = NULL;

 ICARDCONTAINER_QueryInterface(m_pCardContainer, AEEIID_WIDGET, (void**)&pCardContainerWig);
 IDECORATOR_SetWidget((IDecorator *)m_pTabWidget, pCardContainerWig);
 IWIDGET_SetModel(m_pTabWidget,(IModel*)m_pVectorModel);

 for( int i = 0 ; i < 2 ; i++ )
 {
  int Image_id = IDI_OBJECT_5001 + i;
  int String_id = IDS_STRING_1001 + i;

  pImageTitle = ISHELL_LoadResImage(m_pShell, TABAPP_RES_FILE, Image_id);
  pStaticText = (AECHAR*)MALLOC(100);
  ISHELL_LoadResString(m_pShell, TABAPP_RES_FILE, String_id, pStaticText, 100);
  m_ImageStaticInfo[i].pwText = pStaticText;
  m_ImageStaticInfo[i].piImage = pImageTitle;
  IVECTORMODEL_Add(m_pVectorModel, &(m_ImageStaticInfo[i]));
 }
 
 IVECTORMODEL_SetPfnFree(m_pVectorModel, FreeVectorModel);//设置调用回调函数释放在VectorModel中的项目
 
 IWIDGET_SetFlags(m_pTabWidget, TABWF_SHOWTEXTALWAYS | TABWF_WRAP | TABWF_SHOWBORDER);
 IWIDGET_SetPadding(m_pTabWidget, 0);
 IWIDGET_SetActiveBorderWidth(m_pTabWidget, 2);
 IWIDGET_SetInactiveBorderWidth(m_pTabWidget, 1);
 IWIDGET_SetInactiveBorderColor(m_pTabWidget, MAKE_RGBA(0x7B,0x7D,0xA5,255));
 IWIDGET_SetActiveBorderColor(m_pTabWidget,MAKE_RGBA(0x7B,0x7D,0xA5,255));
 IWIDGET_SetInactiveBGColor(m_pTabWidget, MAKE_RGBA(0xEF,0xEF,0xFF,255)); 
 IWIDGET_SetActiveBGColor(m_pTabWidget, MAKE_RGBA(0xc0,0xff,0xe0,255));
 IFORM_SetWidget(m_pForm, WID_FORM, m_pTabWidget);
 
 return TRUE;
}

void BaseWin::FreeAppData(BaseWin* pMe)
{
 RELEASEIF(pMe->m_pForm);
 RELEASEIF(pMe->m_pCardContainer);
 RELEASEIF(pMe->m_pTabWidget);
 RELEASEIF(pMe->m_pVectorModel);
}

void BaseWin::FreeVectorModel(void* pData)
{
 ImageStaticInfo *pImgstaItem = (ImageStaticInfo *)pData;
 IImage_Release(pImgstaItem->piImage);
}

int BaseWin::ShowForm(IRootForm* pRootForm)
{
 return IROOTFORM_PushForm(pRootForm,m_pForm);
}

 

5、编写TabApp.h文件

 

#ifndef TABAPP_H_
#define TABAPP_H_

#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "AEEFile.h"   // File interface definitions
#include "AEEDB.h"    // Database interface definitions
#include "AEENet.h"    // Socket interface definitions
#include "AEESound.h"   // Sound Interface definitions
#include "AEETapi.h"   // TAPI Interface definitions

#include "TabApp.bid"
#include "TabApp.brh"
#include "Includer.h"
#include "Helper.h"

#include "BaseWin.h"

class TabApp : public AEEApplet
{
public:
 TabApp();
 ~TabApp();
public:
 static boolean HandleEvent(TabApp* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam);
 static boolean InitAppData(TabApp* pMe);
 static void FreeAppData(TabApp* pMe);
 static void OnStart(TabApp* pMe);
public:
 AEEDeviceInfo m_DeviceInfo;
 IRootForm*  m_pRootForm;
};

#endif

 

6、编写TabApp.cpp文件

 

#include "TabApp.h"

/*===========================================================================*/
extern "C"
{
 int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)
 {
  *ppObj = NULL;

  if( ClsId == AEECLSID_TABAPP )
  {
   // Create the applet and make room for the applet structure
   if( AEEApplet_New(sizeof(TabApp),
    ClsId,
    pIShell,
    po,
    (IApplet**)ppObj,
    (AEEHANDLER)TabApp::HandleEvent,
    (PFNFREEAPPDATA)TabApp::FreeAppData) ) // the FreeAppData function is called after sending EVT_APP_STOP to the HandleEvent function

   {
    //Initialize applet data, this is called before sending EVT_APP_START
    // to the HandleEvent function
    if(TabApp::InitAppData((TabApp*)*ppObj))
    {
     //Data initialized successfully
     return(AEE_SUCCESS);
    }
    else
    {
     //Release the applet. This will free the memory allocated for the applet when
     // AEEApplet_New was called.
     IAPPLET_Release((IApplet*)*ppObj);
     return EFAILED;
    }

   } // end AEEApplet_New

  }

  return(EFAILED);
 }

}

/*===========================================================================*/

TabApp::TabApp():m_pRootForm(NULL)
{

}

TabApp::~TabApp()
{

}

/*===========================================================================*/
boolean TabApp::HandleEvent(TabApp* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)

 if(IROOTFORM_HandleEvent(pMe->m_pRootForm, eCode, wParam, dwParam))
  return TRUE;
    switch (eCode)
 {
        // App is told it is starting up
        case EVT_APP_START:                       
      // Add your code here...
   pMe->OnStart(pMe);
            return(TRUE);


        // App is told it is exiting
        case EVT_APP_STOP:
            // Add your code here...

        return(TRUE);


        // App is being suspended
        case EVT_APP_SUSPEND:
      // Add your code here...

        return(TRUE);


        // App is being resumed
        case EVT_APP_RESUME:
      // Add your code here...

        return(TRUE);


        // An SMS message has arrived for this app. 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:
      // Add your code here...

        return(TRUE);

        // A key was pressed. Look at the wParam above to see which key was pressed. The key
        // codes are in AEEVCodes.h. Example "AVK_1" means that the "1" key was pressed.
        case EVT_KEY:
      // Add your code here...

        return(TRUE);
   // Flip event. Look at the wParam above to know flip state.
        case EVT_FLIP:
   // wParam = FALSE, when flip is closed.
   if(wParam == FALSE)
   {
        
   }   
   else
   {    
     
   }
  
   return(TRUE);

    // Key-guard event. Look at the wParam above to know key-guard state.
        case EVT_KEYGUARD:

   // wParam = TRUE, when key-guard is enabled.
   if(wParam == TRUE)
   {
     
   }   
   else
   {    
     
   } 
    
        return(TRUE); 

        // If nothing fits up to this point then we'll just break out
        default:
            break;
   }

   return FALSE;
}


// this function is called when your application is starting up
boolean TabApp::InitAppData(TabApp* pMe)
{
    pMe->m_DeviceInfo.wStructSize = sizeof(pMe->m_DeviceInfo);
    ISHELL_GetDeviceInfo(pMe->m_pIShell,&pMe->m_DeviceInfo);
    // Insert your code here for initializing or allocating resources...

 ISHELL_CreateInstance(pMe->m_pIShell,AEECLSID_ROOTFORM,(void**)&pMe->m_pRootForm);

 IROOTFORM_HandleEvent(pMe->m_pRootForm,EVT_WDG_ENABLETOUCH,0,1);//设置窗体触摸

    return TRUE;
}

// this function is called when your application is exiting
void TabApp::FreeAppData(TabApp* pMe)
{
 RELEASEIF(pMe->m_pRootForm);
}

void TabApp::OnStart(TabApp* pMe)
{
 BaseWin* pBaseWin = new BaseWin(pMe->m_pIShell,pMe->m_pRootForm);
 pBaseWin->InitAppData();
 pBaseWin->ShowForm(pMe->m_pRootForm);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值