mirror of
https://gitee.com/idea4good/GuiLite.git
synced 2026-01-08 17:34:46 +08:00
!31 Remove cmd_target, refact timer
This commit is contained in:
@@ -48,7 +48,7 @@ T_TIME second_to_day(long second);
|
||||
T_TIME get_time();
|
||||
|
||||
void start_real_timer(void (*func)(void* arg));
|
||||
void register_timer(int milli_second, void func(void* ptmr, void* parg));
|
||||
void register_timer(int milli_second, void func(void* param), void* param);
|
||||
|
||||
unsigned int get_cur_thread_id();
|
||||
void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg);
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#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
|
||||
{
|
||||
unsigned int msgType;
|
||||
unsigned int msgId;
|
||||
c_cmd_target* object;
|
||||
msgCallback callBack;
|
||||
};
|
||||
|
||||
#define ON_GL_USER_MSG(msgId, func) \
|
||||
{MSG_TYPE_USR, msgId, 0, msgCallback(&func)},
|
||||
|
||||
#define GL_DECLARE_MESSAGE_MAP() \
|
||||
protected: \
|
||||
virtual const GL_MSG_ENTRY* get_msg_entries() const;\
|
||||
private: \
|
||||
static const GL_MSG_ENTRY m_msg_entries[];
|
||||
|
||||
#define GL_BEGIN_MESSAGE_MAP(theClass) \
|
||||
const GL_MSG_ENTRY* theClass::get_msg_entries() const \
|
||||
{ \
|
||||
return theClass::m_msg_entries; \
|
||||
} \
|
||||
const GL_MSG_ENTRY theClass::m_msg_entries[] = \
|
||||
{
|
||||
|
||||
#define GL_END_MESSAGE_MAP() \
|
||||
{MSG_TYPE_INVALID, 0, 0, 0}};
|
||||
|
||||
class c_cmd_target
|
||||
{
|
||||
public:
|
||||
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* 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);
|
||||
}
|
||||
ms_usr_map_entries[ms_user_map_size] = *p_entry;
|
||||
ms_usr_map_entries[ms_user_map_size].object = this;
|
||||
ms_user_map_size++;
|
||||
}
|
||||
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;
|
||||
GL_DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
@@ -52,9 +52,10 @@ typedef struct struct_wnd_tree
|
||||
struct struct_wnd_tree* p_child_tree;//sub tree
|
||||
}WND_TREE;
|
||||
|
||||
class c_wnd : public c_cmd_target
|
||||
typedef void (c_wnd::*WND_CALLBACK)(int, int);
|
||||
|
||||
class c_wnd
|
||||
{
|
||||
friend class c_dialog;
|
||||
public:
|
||||
c_wnd() : m_status(STATUS_NORMAL), m_attr((WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS)), m_parent(0), m_top_child(0), m_prev_sibling(0), m_next_sibling(0),
|
||||
m_str(0), m_font_color(0), m_bg_color(0), m_id(0), m_z_order(Z_ORDER_LEVEL_0), m_focus_child(0), m_surface(0) {};
|
||||
@@ -99,7 +100,6 @@ public:
|
||||
|
||||
if (load_child_wnd(p_child_tree) >= 0)
|
||||
{
|
||||
load_cmd_msg();
|
||||
on_init_children();
|
||||
}
|
||||
return 0;
|
||||
@@ -303,20 +303,6 @@ public:
|
||||
c_wnd* get_prev_sibling() const { return m_prev_sibling; }
|
||||
c_wnd* get_next_sibling() const { return m_next_sibling; }
|
||||
|
||||
void notify_parent(int msg_id, int param)
|
||||
{
|
||||
if (!m_parent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const GL_MSG_ENTRY* entry = m_parent->find_msg_entry(m_parent->get_msg_entries(), MSG_TYPE_WND, msg_id);
|
||||
if (0 == entry)
|
||||
{
|
||||
return;
|
||||
}
|
||||
(m_parent->*(entry->callBack))(m_id, param);
|
||||
}
|
||||
|
||||
virtual void on_touch(int x, int y, TOUCH_ACTION action)
|
||||
{
|
||||
x -= m_wnd_rect.m_left;
|
||||
@@ -501,6 +487,7 @@ protected:
|
||||
virtual void on_focus() {};
|
||||
virtual void on_kill_focus() {};
|
||||
protected:
|
||||
unsigned short m_id;
|
||||
WND_STATUS m_status;
|
||||
WND_ATTRIBUTION m_attr;
|
||||
c_rect m_wnd_rect; //position relative to parent window.
|
||||
@@ -508,18 +495,13 @@ protected:
|
||||
c_wnd* m_top_child; //the first sub window would be navigated
|
||||
c_wnd* m_prev_sibling; //previous brother
|
||||
c_wnd* m_next_sibling; //next brother
|
||||
c_wnd* m_focus_child; //current focused window
|
||||
const char* m_str; //caption
|
||||
|
||||
const FONT_INFO* m_font_type;
|
||||
unsigned int m_font_color;
|
||||
unsigned int m_bg_color;
|
||||
|
||||
unsigned short m_id;
|
||||
|
||||
int m_z_order; //the graphic level for rendering
|
||||
c_wnd* m_focus_child; //current focused window
|
||||
c_surface* m_surface;
|
||||
private:
|
||||
c_wnd(const c_wnd &win);
|
||||
c_wnd& operator=(const c_wnd &win);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user