mirror of
https://gitee.com/idea4good/GuiLite.git
synced 2026-01-02 12:27:22 +08:00
!27 Support header-only
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
#ifndef GUILITE_CORE_INCLUDE_CMD_TARGET_H
|
||||
#define GUILITE_CORE_INCLUDE_CMD_TARGET_H
|
||||
|
||||
class c_cmd_target;
|
||||
#include "../core_include/api.h"
|
||||
|
||||
#define MSG_TYPE_INVALID 0xFFFF
|
||||
#define MSG_TYPE_WND 0x0001
|
||||
#define MSG_TYPE_USR 0x0002
|
||||
#define USR_MSG_MAX 32
|
||||
|
||||
class c_cmd_target;
|
||||
typedef void (c_cmd_target::*msgCallback)(int, int);
|
||||
|
||||
struct GL_MSG_ENTRY
|
||||
@@ -41,10 +42,92 @@ const GL_MSG_ENTRY theClass::m_msg_entries[] = \
|
||||
class c_cmd_target
|
||||
{
|
||||
public:
|
||||
static int handle_usr_msg(int msg_id, int resource_id, int param);
|
||||
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;
|
||||
}
|
||||
protected:
|
||||
void load_cmd_msg();
|
||||
const GL_MSG_ENTRY* find_msg_entry(const GL_MSG_ENTRY *pEntry, int msgType, int msgId);
|
||||
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)
|
||||
{
|
||||
ms_usr_map_entries[ms_user_map_size] = *p_entry;
|
||||
ms_usr_map_entries[ms_user_map_size].object = this;
|
||||
ms_user_map_size++;
|
||||
if (USR_MSG_MAX == ms_user_map_size)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
private:
|
||||
static GL_MSG_ENTRY ms_usr_map_entries[USR_MSG_MAX];
|
||||
static unsigned short ms_user_map_size;
|
||||
|
||||
Reference in New Issue
Block a user