/*==========================================
FILE: IEventList.c
内容:イベント設定
作者:ウィリアムのいたずら
============================================*/
/*===========================================
INCLUDES AND VARIABLE DEFINITIONS
============================================*/
#define _IEVENTLIST_C
#include "IEventList.h"
/*==========================================
FUNCTION DEFINITIONS
============================================*/
//==========================================//
// 関数名:IEVENTLIST_Create //
// 内容 :イベントリストの生成 //
//==========================================//
IEventList *IEVENTLIST_Create()
{
IEventList *pMe;
// メモリ領域確保
pMe = NULL;
if ( (pMe = MALLOC(sizeof(IEventList))) == NULL )
{
return NULL;
}
// 初期化
pMe->eventsu = 0;
pMe->eCode = NULL;
pMe->wParam = NULL;
pMe->dwParam = NULL;
pMe->func = NULL;
pMe->pArg = NULL;
return pMe;
}
//==========================================//
// 関数名:IEVENTLIST_Release //
// 内容 :イベントリストの解放 //
//==========================================//
void IEVENTLIST_Release(IEventList *pMe)
{
if ( pMe == NULL )
return;
if ( pMe->kind != NULL)
{
FREEIF(pMe->kind);
}
if ( pMe->eCode != NULL)
{
FREEIF(pMe->eCode);
}
if ( pMe->wParam != NULL)
{
FREEIF(pMe->wParam);
}
if ( pMe->dwParam != NULL)
{
FREEIF(pMe->dwParam);
}
if ( pMe->func != NULL)
{
FREEIF(pMe->func);
}
if ( pMe->pArg != NULL)
{
FREEIF(pMe->pArg);
}
FREEIF(pMe);
}
//==========================================//
// 関数名:IEVENTLIST_Add //
// 内容 :イベントリスト追加 //
//==========================================//
int IEVENTLIST_Add(IEventList *pMe,void *pArg,int kind,AEEEvent eCode,
uint16 wParam,uint32 dwParam,PFNAEEEVENT func)
{
int n_eventsu;
int *n_kind;
AEEEvent *n_eCode;
uint16 *n_wParam;
uint32 *n_dwParam;
PFNAEEEVENT *n_func;
void **n_pArg;
if ( pMe == NULL )
return -1;
// 新しい領域確保
n_eventsu = pMe->eventsu + 1;
n_kind = (int *)MALLOC(n_eventsu * sizeof(int));
n_eCode = (AEEEvent *)MALLOC(n_eventsu * sizeof(AEEEvent));
n_wParam = (uint16 *)MALLOC(n_eventsu * sizeof(uint16));
n_dwParam = (uint32 *)MALLOC(n_eventsu * sizeof(uint32));
n_func = (PFNAEEEVENT *)MALLOC(n_eventsu * sizeof(PFNAEEEVENT));
n_pArg = (void **)MALLOC(n_eventsu * sizeof(void *));
// 古い領域のコピーと解放
if ( pMe->eventsu != 0 )
{
MEMCPY(n_kind,pMe->kind,pMe->eventsu * sizeof(int));
FREEIF(pMe->kind);
MEMCPY(n_eCode,pMe->eCode,pMe->eventsu * sizeof(AEEEvent));
FREEIF(pMe->eCode);
MEMCPY(n_wParam,pMe->wParam,pMe->eventsu * sizeof(uint16));
FREEIF(pMe->wParam);
MEMCPY(n_dwParam,pMe->dwParam,pMe->eventsu * sizeof(uint32));
FREEIF(pMe->dwParam);
MEMCPY(n_func,pMe->func,pMe->eventsu * sizeof(PFNAEEEVENT));
FREEIF(pMe->func);
MEMCPY(n_pArg,pMe->pArg,pMe->eventsu * sizeof(void *));
FREEIF(pMe->pArg);
}
// 新しい領域を転送
pMe->eventsu = n_eventsu;
pMe->kind = n_kind;
pMe->eCode = n_eCode;
pMe->wParam = n_wParam;
pMe->dwParam = n_dwParam;
pMe->func = n_func;
pMe->pArg = n_pArg;
// 新しい値を転送
n_eventsu --; // 配列の最後は、個数 -1
pMe->kind[n_eventsu] = kind;
pMe->eCode[n_eventsu] = eCode;
pMe->wParam[n_eventsu] = wParam;
pMe->dwParam[n_eventsu] = dwParam;
pMe->func[n_eventsu] = func;
pMe->pArg[n_eventsu] = pArg;
return 0;
}
//===========================================//
// 関数名:IEVENTLIST_HandleEvent //
// 内容 :イベントリストのイベント処理//
//===========================================//
boolean IEVENTLIST_HandleEvent(IEventList *pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam)
{
int i;
// 引数チェック
if ( pMe == NULL )
{
return FALSE;
}
for(i = 0 ; i < pMe->eventsu ; i ++ )
{
switch(pMe->kind[i])
{
case IEVENTLIST_KIND_ECODE:
if ( eCode == pMe->eCode[i] )
{
return (pMe->func[i])(pMe->pArg[i],
eCode,wParam,dwParam);
}
break;
case IEVENTLIST_KIND_WPARAM:
if ( ( eCode == pMe->eCode[i] ) &&
( wParam == pMe->wParam[i]) )
{
return (pMe->func[i])(pMe->pArg[i],
eCode,wParam,dwParam);
}
break;
case IEVENTLIST_KIND_DWPARAM:
if ( ( eCode == pMe->eCode[i] ) &&
( wParam == pMe->wParam[i]) &&
( dwParam == pMe->dwParam[i]) )
{
return (pMe->func[i])(pMe->pArg[i],
eCode,wParam,dwParam);
}
break;
}
}
return FALSE;
}
|