📄 phonebooks.c
字号:
/*===========================================================================
FILE: PhoneBooks.c
===========================================================================*/
/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#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 "PhoneBooks.bid"
#include "PhoneBooks.h"
/*===========================================================================
FUNCTION: AEEClsCreateInstance
DESCRIPTION
This function is invoked while the app is being loaded. All Modules must provide this
function. Ensure to retain the same name and parameters for this function.
In here, the module must verify the ClassID and then invoke the AEEApplet_New() function
that has been provided in AEEAppGen.c.
After invoking AEEApplet_New(), this function can do app specific initialization. In this
example, a generic structure is provided so that app developers need not change app specific
initialization section every time except for a call to IDisplay_InitAppData().
This is done as follows: InitAppData() is called to initialize AppletData
instance. It is app developers responsibility to fill-in app data initialization
code of InitAppData(). App developer is also responsible to release memory
allocated for data contained in AppletData -- this can be done in
IDisplay_FreeAppData().
PROTOTYPE:
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
PARAMETERS:
clsID: [in]: Specifies the ClassID of the applet which is being loaded
pIShell: [in]: Contains pointer to the IShell object.
pIModule: pin]: Contains pointer to the IModule object to the current module to which
this app belongs
ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
of memory for this structure and initializing the base data members is done by AEEApplet_New().
DEPENDENCIES
none
RETURN VALUE
AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
successful
EFAILED: If the app does not need to be loaded or if errors occurred in
AEEApplet_New(). If this function returns FALSE, the app will not be loaded.
SIDE EFFECTS
none
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
*ppObj = NULL;
if(ClsId == AEECLSID_PHONEBOOKS){
if(AEEApplet_New(sizeof(CPhoneBooks), ClsId, pIShell,po,(IApplet**)ppObj,
(AEEHANDLER)CPhoneBooks_HandleEvent,(PFNFREEAPPDATA)CPhoneBooks_FreeAppData)
== TRUE)
{
// Add your code here .....
if(CPhoneBooks_InitAppData((IApplet*)*ppObj)==TRUE)
{
//Data initialized successfully
return(AEE_SUCCESS);
}
else
{
//Release the applet. This will free the memory allocated for the applet when
IAPPLET_Release((IApplet*)*ppObj);
*ppObj = NULL;
return EFAILED;
}
return (AEE_SUCCESS);
}
}
return (EFAILED);
}
IWindow * CWindow_New(int16 nSize, CPhoneBooks * pOwner, VTBL(IWindow) * pvt)
{
//CWindow基类构造函数.所有派生类都要调用它来实例化
CWindow * pme;
VTBL(IWindow) * pVtbl;
pme = MALLOC(nSize + sizeof(VTBL(IWindow)));
if (!pme)
return NULL;
pme->m_pOwner = pOwner;
pme->m_pIShell = pme->m_pOwner->a.m_pIShell;
pme->m_pIDisplay = pme->m_pOwner->a.m_pIDisplay;
pme->m_bActive=FALSE;
pVtbl = (VTBL(IWindow) *)((byte *)pme + nSize);
MEMCPY(pVtbl, pvt, sizeof(VTBL(IWindow)));
INIT_VTBL(pme, IWindow, *pVtbl);
return (IWindow *)pme;
}
boolean CPhoneBooks_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
CPhoneBooks* pme=(CPhoneBooks*)pi;
boolean is=TRUE;
switch (eCode)
{
case EVT_APP_START:
// Add your code here .....
if(pme->m_pWin)
IWINDOW_Redraw(pme->m_pWin);
return(TRUE);
case EVT_APP_STOP:
// Add your code here .....
return TRUE;
default:
break;
}
if(pme->m_pWin)
is=IWINDOW_HandleEvent(pme->m_pWin,eCode,wParam,dwParam);
return is;
}
boolean CPhoneBooks_InitAppData(IApplet* po)
{
CPhoneBooks* pme = (CPhoneBooks*)po;
int nAscent,nDescent;
AEEDeviceInfo* pdi;
//得到设备信息
pdi = MALLOC(sizeof(AEEDeviceInfo));
if (!pdi)
return FALSE;
ISHELL_GetDeviceInfo(pme->a.m_pIShell, pdi);
pme->m_cxWidth = pdi->cxScreen;
pme->m_cyHeight = pdi->cyScreen;
pme->m_nColorDepth = pdi->nColorDepth;
FREEIF(pdi);
IDISPLAY_GetFontMetrics(pme->a.m_pIDisplay, AEE_FONT_LARGE, &nAscent, &nDescent);
pme->m_nLChSize = nAscent + nDescent;
IDISPLAY_GetFontMetrics(pme->a.m_pIDisplay, AEE_FONT_NORMAL, &nAscent, &nDescent);
pme->m_nNChSize = nAscent + nDescent;
if(ISHELL_CreateInstance(pme->a.m_pIShell,AEECLSID_ADDRBOOK,&pme->m_pAddrBook)!=SUCCESS)
return FALSE;
CPhoneBooks_SetWindow(pme,W_LIST,NULL);
return TRUE;
}
boolean CPhoneBooks_SetWindow(CPhoneBooks * pme, WINTYPE eWin, uint32 dwParam)
{
//所有CWindow应用框架结构都要实现此函数,用于构造、切换窗口
//是否有必要重绘.确保窗口被反复激活时不会重绘
if (pme->m_pWin && pme->m_eWin == eWin && eWin != W_NONE)
{
IWINDOW_Redraw(pme->m_pWin);
return TRUE;
}
RELEASE_Win(pme->m_pWin);
IDISPLAY_ClearScreen(pme->a.m_pIDisplay);
//窗口切换
switch (eWin)
{
case W_LIST:
pme->m_pWin=CListWin_New(pme);
break;
case W_FORM:
pme->m_pWin=CFormWin_New(pme);
if(dwParam!=NULL)
{
IAddrRec* pAbr=NULL;
int m,n,i,j;
AEEAddrField* pAbF=NULL;
((CFormWin*)(pme->m_pWin))->nRecID=dwParam;
pAbr=IADDRBOOK_GetRecByID(pme->m_pAddrBook,dwParam-1);
if(!pAbr)
return FALSE;
IMENUCTL_SetSel(((CFormWin*)(pme->m_pWin))->pGroupBox, \
IADDRREC_GetCategory(pAbr)+100-AEE_ADDR_CAT_USER_DEFINED);
n=IADDRREC_GetFieldCount(pAbr);
for(i=0;i<n;i++)
{
pAbF=IADDRREC_GetField(pAbr,i);
if(pAbF==NULL)
{
RELEASE_Ctl(&pAbr);
return FALSE;
}
switch(pAbF->fID)
{
case AEE_ADDRFIELD_NAME:
ITEXTCTL_SetText(((CFormWin*)(pme->m_pWin))->pNameBox,pAbF->pBuffer,-1);
break;
case AEE_ADDRFIELD_PHONE_HOME:
ITEXTCTL_SetText(((CFormWin*)(pme->m_pWin))->pPhoneBox,pAbF->pBuffer,-1);
break;
case AEE_ADDRFIELD_PHONE_GENERIC:
ITEXTCTL_SetText(((CFormWin*)(pme->m_pWin))->pMobileBox,pAbF->pBuffer,-1);
break;
default:
break;
}
}
RELEASE_Ctl(&pAbr);
}
break;
case W_NONE:
return TRUE;
break;
default:
return FALSE;
break;
}
if (!pme->m_pWin)
{
eWin = W_NONE;
return FALSE;
}
pme->m_eWin = eWin;
IWINDOW_Redraw(pme->m_pWin);
return TRUE;
}
static void CPhoneBooks_FreeAppData(IApplet* po)
{
CPhoneBooks * pme = (CPhoneBooks *)po;
pme->m_eWin=W_NONE;
RELEASE_Win(pme->m_pWin);
RELEASE_Ctl(&pme->m_pAddrBook);
}
IWindow* CListWin_New(CPhoneBooks * pOwner)
{
CListWin* pme;
VTBL(IWindow) vtbl;
AEERect rect;
IAddrRec* pAbr=NULL;
int m,n,i,j;
AEEAddrField* pAbF=NULL;
uint32 data;
//继承自CWindow的类必须如此构造
IWINDOW_SETVTBL(&vtbl, CListWin_Enable, CListWin_Redraw, CListWin_HandleEvent, CListWin_Delete);
pme = (CListWin *)CWindow_New(sizeof(CListWin), pOwner, &vtbl);
if (!pme)
return NULL;
//派生类私有成员构造
//软键菜单
pme->pSoftMenuCtl=CSoftMenuCtl_New(pOwner);
if(!pme->pSoftMenuCtl)
return NULL;
CSoftMenuCtl_SetBackground(pme->pSoftMenuCtl,FALSE,NULL,MAKE_RGB(0,0,255));
CSoftMenuCtl_SetSoftKey(pme->pSoftMenuCtl,0,L"选项",L"编辑");
//纵向名称列表
if(ISHELL_CreateInstance(pme->m_pIShell,AEECLSID_MENUCTL,&pme->pVListCtl)!=SUCCESS)
return NULL;
SETAEERECT(&rect,0,0,pme->m_pOwner->m_cxWidth/2,pme->m_pOwner->m_cyHeight-4*pme->pSoftMenuCtl->m_Rect.dy);
IMENUCTL_SetRect(pme->pVListCtl,&rect);
{
AEEMenuColors colors;
AEEItemStyle style;
colors.wMask=MC_BACK|MC_TEXT|MC_SEL_BACK|MC_SEL_TEXT|MC_FRAME| \
MC_SCROLLBAR|MC_SCROLLBAR_FILL|MC_TITLE|MC_TITLE_TEXT;
colors.cBack=MAKE_RGB(255,255,255);
colors.cText=MAKE_RGB(0,0,0);
colors.cSelBack=MAKE_RGB(0,0,255);
colors.cSelText=MAKE_RGB(255,255,255);
colors.cFrame=MAKE_RGB(0,0,0);
colors.cScrollbar=MAKE_RGB(150,150,150);
colors.cScrollbarFill=MAKE_RGB(0,0,255);
colors.cTitle=MAKE_RGB(255,255,255);
colors.cTitleText=MAKE_RGB(0,0,0);
style.ft=AEE_FT_EMPTY;
style.roImage=0;
style.xOffset=0;
style.yOffset=0;
IMENUCTL_SetColors(pme->pVListCtl,&colors);
IMENUCTL_SetStyle(pme->pVListCtl,&style,&style);
IMENUCTL_SetTitle(pme->pVListCtl,NULL,NULL,L"电话簿");
}
if(IADDRBOOK_EnumRecInit(pme->m_pOwner->m_pAddrBook, \
AEE_ADDR_CAT_NONE,AEE_ADDRFIELD_NONE,NULL,NULL)!=AEE_SUCCESS)
return NULL;
m=IADDRBOOK_GetNumRecs(pme->m_pOwner->m_pAddrBook);
for(j=0;j<m;j++)
{
pAbr=IADDRBOOK_EnumNextRec(pme->m_pOwner->m_pAddrBook);
if(!pAbr)
{
break;
}
n=IADDRREC_GetFieldCount(pAbr);
for(i=0;i<n;i++)
{
pAbF=IADDRREC_GetField(pAbr,i);
if(pAbF==NULL)
{
RELEASE_Ctl(&pAbr);
return NULL;
}
if(pAbF->fID==AEE_ADDRFIELD_NAME)
{
IMENUCTL_AddItem(pme->pVListCtl,NULL,NULL,1000+j,pAbF->pBuffer,IADDRREC_GetRecID(pAbr));
break;
}
}
RELEASE_Ctl(&pAbr);
}
//显示字段值
if(ISHELL_CreateInstance(pme->m_pIShell,AEECLSID_STATIC,&pme->pStaticCtl)!=SUCCESS)
return NULL;
SETAEERECT(&rect,0,rect.y+rect.dy,pme->m_pOwner->m_cxWidth,pme->pSoftMenuCtl->m_Rect.dy);
ISTATIC_SetRect(pme->pStaticCtl,&rect);
//显示照片.未完成???
pme->pPhotoCtl=ISHELL_LoadResImage(pme->m_pIShell,PHONEBOOKS_RES_FILE,PHOTO);
if(pme->pPhotoCtl==NULL)
return NULL;
//横向字段类型列表
if(ISHELL_CreateInstance(pme->m_pIShell,AEECLSID_SOFTKEYCTL,&pme->pHListCtl)!=SUCCESS)
return NULL;
SETAEERECT(&rect,0,rect.y+rect.dy,pme->m_pOwner->m_cxWidth,2*pme->pSoftMenuCtl->m_Rect.dy);
IMENUCTL_SetRect(pme->pHListCtl,&rect);
if(IMENUCTL_GetItemCount(pme->pVListCtl)>0)
{
IMENUCTL_GetItemData(pme->pVListCtl,IMENUCTL_GetSel(pme->pVListCtl),&data);
pAbr=IADDRBOOK_GetRecByID(pme->m_pOwner->m_pAddrBook,data);
if(!pAbr)
return NULL;
n=IADDRREC_GetFieldCount(pAbr);
for(i=0;i<n;i++)
{
CtlAddItem item;
item.pText=NULL;
item.pImage=NULL;
item.pszResText=NULL;
item.pszResImage=PHONEBOOKS_RES_FILE;
item.wText=0;
item.wFont=0;
pAbF=IADDRREC_GetField(pAbr,i);
if(pAbF==NULL)
{
RELEASE_Ctl(&pAbr);
return NULL;
}
switch(pAbF->fID)
{
case AEE_ADDRFIELD_PHONE_HOME:
if(WSTRLEN(pAbF->pBuffer)>0)
{
item.wItemID=2000;
item.dwData=i;
item.wImage=PHONE;
IMENUCTL_AddItemEx(pme->pHListCtl,&item);
}
break;
case AEE_ADDRFIELD_PHONE_GENERIC:
if(WSTRLEN(pAbF->pBuffer)>0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -