2019-08-19 16:03:27 +08:00
|
|
|
#ifndef GUILITE_CORE_INCLUDE_CMD_TARGET_H
|
|
|
|
#define GUILITE_CORE_INCLUDE_CMD_TARGET_H
|
2017-12-06 21:43:47 +08:00
|
|
|
|
2020-01-22 11:03:29 +08:00
|
|
|
#include "../core_include/api.h"
|
2017-12-06 21:43:47 +08:00
|
|
|
|
|
|
|
#define MSG_TYPE_INVALID 0xFFFF
|
|
|
|
#define MSG_TYPE_WND 0x0001
|
|
|
|
#define MSG_TYPE_USR 0x0002
|
2019-03-13 11:11:29 +08:00
|
|
|
#define USR_MSG_MAX 32
|
2017-12-06 21:43:47 +08:00
|
|
|
|
2020-01-22 11:03:29 +08:00
|
|
|
class c_cmd_target;
|
2019-12-17 10:45:15 +08:00
|
|
|
typedef void (c_cmd_target::*msgCallback)(int, int);
|
2017-12-06 21:43:47 +08:00
|
|
|
|
2018-12-02 22:39:43 +08:00
|
|
|
struct GL_MSG_ENTRY
|
2017-12-06 21:43:47 +08:00
|
|
|
{
|
|
|
|
unsigned int msgType;
|
|
|
|
unsigned int msgId;
|
2019-12-17 10:45:15 +08:00
|
|
|
c_cmd_target* object;
|
|
|
|
msgCallback callBack;
|
2017-12-06 21:43:47 +08:00
|
|
|
};
|
|
|
|
|
2020-09-10 14:28:42 +08:00
|
|
|
#define ON_GL_USER_MSG(msgId, func) \
|
2019-12-17 10:45:15 +08:00
|
|
|
{MSG_TYPE_USR, msgId, 0, msgCallback(&func)},
|
2017-12-06 21:43:47 +08:00
|
|
|
|
2018-12-02 22:39:43 +08:00
|
|
|
#define GL_DECLARE_MESSAGE_MAP() \
|
2017-12-06 21:43:47 +08:00
|
|
|
protected: \
|
2019-12-17 10:45:15 +08:00
|
|
|
virtual const GL_MSG_ENTRY* get_msg_entries() const;\
|
2017-12-06 21:43:47 +08:00
|
|
|
private: \
|
2019-12-17 10:45:15 +08:00
|
|
|
static const GL_MSG_ENTRY m_msg_entries[];
|
2017-12-06 21:43:47 +08:00
|
|
|
|
2018-12-02 22:39:43 +08:00
|
|
|
#define GL_BEGIN_MESSAGE_MAP(theClass) \
|
2019-12-17 10:45:15 +08:00
|
|
|
const GL_MSG_ENTRY* theClass::get_msg_entries() const \
|
2017-12-06 21:43:47 +08:00
|
|
|
{ \
|
2019-12-17 10:45:15 +08:00
|
|
|
return theClass::m_msg_entries; \
|
2017-12-06 21:43:47 +08:00
|
|
|
} \
|
2019-12-17 10:45:15 +08:00
|
|
|
const GL_MSG_ENTRY theClass::m_msg_entries[] = \
|
2017-12-06 21:43:47 +08:00
|
|
|
{
|
|
|
|
|
2020-09-10 14:28:42 +08:00
|
|
|
#define GL_END_MESSAGE_MAP() \
|
2019-12-17 10:45:15 +08:00
|
|
|
{MSG_TYPE_INVALID, 0, 0, 0}};
|
2017-12-06 21:43:47 +08:00
|
|
|
|
|
|
|
class c_cmd_target
|
|
|
|
{
|
|
|
|
public:
|
2020-01-22 11:03:29 +08:00
|
|
|
static int handle_usr_msg(int msg_id, int resource_id, int param)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
c_cmd_target* p_wnd = 0;
|
|
|
|
for (i = 0; i < ms_user_map_size; i++)
|
|
|
|
{
|
|
|
|
if (msg_id == ms_usr_map_entries[i].msgId)
|
|
|
|
{
|
|
|
|
p_wnd = (c_cmd_target*)ms_usr_map_entries[i].object;
|
|
|
|
(p_wnd->*ms_usr_map_entries[i].callBack)(resource_id, param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2017-12-06 21:43:47 +08:00
|
|
|
protected:
|
2020-01-22 11:03:29 +08:00
|
|
|
void load_cmd_msg()
|
|
|
|
{
|
|
|
|
const GL_MSG_ENTRY* p_entry = get_msg_entries();
|
|
|
|
if (0 == p_entry)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bExist = false;
|
|
|
|
while (MSG_TYPE_INVALID != p_entry->msgType)
|
|
|
|
{
|
|
|
|
if (MSG_TYPE_WND == p_entry->msgType)
|
|
|
|
{
|
|
|
|
p_entry++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bExist = false;
|
|
|
|
for (int i = 0; i < ms_user_map_size; i++)
|
|
|
|
{
|
|
|
|
//repeat register, return.
|
|
|
|
if (p_entry->msgId == ms_usr_map_entries[i].msgId
|
|
|
|
&& ms_usr_map_entries[i].object == this)
|
|
|
|
{
|
|
|
|
bExist = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (true == bExist)
|
|
|
|
{
|
|
|
|
p_entry++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MSG_TYPE_USR == p_entry->msgType)
|
|
|
|
{
|
|
|
|
if (USR_MSG_MAX == ms_user_map_size)
|
|
|
|
{
|
|
|
|
ASSERT(false);
|
|
|
|
}
|
2020-09-28 00:13:50 +08:00
|
|
|
ms_usr_map_entries[ms_user_map_size] = *p_entry;
|
|
|
|
ms_usr_map_entries[ms_user_map_size].object = this;
|
|
|
|
ms_user_map_size++;
|
2020-01-22 11:03:29 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ASSERT(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p_entry++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const GL_MSG_ENTRY* find_msg_entry(const GL_MSG_ENTRY *pEntry, int msgType, int msgId)
|
|
|
|
{
|
|
|
|
if (MSG_TYPE_INVALID == msgType)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (MSG_TYPE_INVALID != pEntry->msgType)
|
|
|
|
{
|
|
|
|
if ((msgType == pEntry->msgType) && (msgId == pEntry->msgId))
|
|
|
|
{
|
|
|
|
return pEntry;
|
|
|
|
}
|
|
|
|
pEntry++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:43:47 +08:00
|
|
|
private:
|
2018-12-02 22:39:43 +08:00
|
|
|
static GL_MSG_ENTRY ms_usr_map_entries[USR_MSG_MAX];
|
2017-12-06 21:43:47 +08:00
|
|
|
static unsigned short ms_user_map_size;
|
2018-12-02 22:39:43 +08:00
|
|
|
GL_DECLARE_MESSAGE_MAP()
|
2017-12-06 21:43:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|