diff --git a/.github/.build-all.sh b/.github/.build-all.sh new file mode 100644 index 0000000000000000000000000000000000000000..6003fc521b63adcb0dc27583b13300f54b0071c2 --- /dev/null +++ b/.github/.build-all.sh @@ -0,0 +1,23 @@ +# exit while meet error +set -e + +# build xWindow +cd ExternalWindow/X11 +gcc xWindow.c -lX11 -lpthread -o xWindow +cd ../.. + +#build HelloXXX +for file in ./Hello* +do + echo -e "\e[44m $file building...\e[49m" + cd $file + cmake . + make -j4 + cd .. +done + +#build HostMonitor +echo -e "\e[44m ./HostMonitor building...\e[49m" +cd HostMonitor +cmake . +make -j4 diff --git a/.github/.updateGuiLite.sh b/.github/.updateGuiLite.sh new file mode 100644 index 0000000000000000000000000000000000000000..be7c59c1af55005120c4a43d3ca000e6bcf28f83 --- /dev/null +++ b/.github/.updateGuiLite.sh @@ -0,0 +1,22 @@ +src=../../GuiLite.gitee +# exit while meet error +set -e +declare -i sum=0 + +#build HelloXXX +for file in ./Hello* +do + echo -e "\e[44m $file sync up...\e[49m" + cd $file + cp $src/GuiLite.h UIcode/GuiLite.h + cd .. + sum+=1 +done + +#build HostMonitor +echo -e "\e[44m ./HostMonitor sync up...\e[49m" +cd HostMonitor +cp $src/GuiLite.h UIcode/include/GuiLite.h +sum+=1 + +echo $sum files updated. diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000000000000000000000000000000000000..a373a672d4afa6f3d77e4e4fcd5803da455ea589 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +custom: https://idea4good.github.io/ diff --git a/.gitignore b/.gitignore index 3cb25d28df1ef43d278db2ebf3107d8bef86a470..1bcad82d2959e2ef6e28ea6338764d8584849b66 100644 --- a/.gitignore +++ b/.gitignore @@ -63,6 +63,8 @@ EventRecorderStub.scvd Makefile* # For output +ExternalWindow/X11/xWindow + libUIcode.a snap_short.bmp @@ -72,7 +74,7 @@ snap_short.bmp /HelloAnimation/BuildLinux/HelloAnimation /HelloCircle/BuildLinux/HelloCircle /HelloFFmpeg/BuildLinux/HelloFFmpeg -/HelloFont/BuildLinux/HelloFFmpeg +/HelloFont/BuildLinux/HelloFont /HelloGuiLite/BuildLinux/HelloGuiLite /HelloLayers/BuildLinux/HelloLayers /HelloMario/BuildLinux/HelloMario @@ -80,6 +82,7 @@ snap_short.bmp /HelloNets/BuildLinux/HelloNets /HelloNoTouch/BuildLinux/HelloNoTouch /HelloParticle/BuildLinux/HelloParticle +/HelloPendulum/BuildLinux/HelloPendulum /HelloScroll/BuildLinux/HelloScroll /HelloSlide/BuildLinux/HelloSlide /HelloStar/BuildLinux/HelloStar diff --git a/Hello3D/UIcode/GuiLite.h b/Hello3D/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/Hello3D/UIcode/GuiLite.h +++ b/Hello3D/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/Hello3Ddonut/UIcode/GuiLite.h b/Hello3Ddonut/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/Hello3Ddonut/UIcode/GuiLite.h +++ b/Hello3Ddonut/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/Hello3Dwave/UIcode/GuiLite.h b/Hello3Dwave/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/Hello3Dwave/UIcode/GuiLite.h +++ b/Hello3Dwave/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloAnimation/UIcode/GuiLite.h b/HelloAnimation/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloAnimation/UIcode/GuiLite.h +++ b/HelloAnimation/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloAnimation/UIcode/UIcode.cpp b/HelloAnimation/UIcode/UIcode.cpp index b655803873eac74117cd2a974b1dc86164dbc14f..bc4d33c673c2ff3208316bf4f3cb6f144b614fcb 100644 --- a/HelloAnimation/UIcode/UIcode.cpp +++ b/HelloAnimation/UIcode/UIcode.cpp @@ -19,6 +19,11 @@ BITMAP_INFO s_frames[] = { frame_00_bmp, frame_01_bmp, frame_02_bmp, frame_03_b class c_myUI : public c_wnd { + virtual void on_init_children() + { + c_button* button = (c_button*)get_wnd_ptr(ID_BUTTON); + button->set_on_click((WND_CALLBACK)&c_myUI::on_clicked); + } virtual void on_paint(void) { c_rect rect; @@ -38,14 +43,8 @@ class c_myUI : public c_wnd thread_sleep(60); } } - GL_DECLARE_MESSAGE_MAP()//delcare message }; -//map message -GL_BEGIN_MESSAGE_MAP(c_myUI) -ON_GL_BN_CLICKED(c_myUI::on_clicked) -GL_END_MESSAGE_MAP() - //////////////////////// layout UI //////////////////////// static c_myUI s_myUI; static c_button s_button; diff --git a/HelloCircle/UIcode/GuiLite.h b/HelloCircle/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloCircle/UIcode/GuiLite.h +++ b/HelloCircle/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloFFmpeg/UIcode/GuiLite.h b/HelloFFmpeg/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloFFmpeg/UIcode/GuiLite.h +++ b/HelloFFmpeg/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloFont/UIcode/GuiLite.h b/HelloFont/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloFont/UIcode/GuiLite.h +++ b/HelloFont/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloFont/UIcode/UIcode.cpp b/HelloFont/UIcode/UIcode.cpp index 7d375fb463cf978905ede834bf5869591b32d931..5a8511f9075ea54fc70cc3a43e277c16b52f60bd 100644 --- a/HelloFont/UIcode/UIcode.cpp +++ b/HelloFont/UIcode/UIcode.cpp @@ -27,6 +27,11 @@ static const char* s_text = "朝辞白帝彩云间千里江陵一日还两岸猿 class c_myUI : public c_wnd { + virtual void on_init_children() + { + c_button* button = (c_button*)get_wnd_ptr(ID_BUTTON); + button->set_on_click((WND_CALLBACK)&c_myUI::on_clicked); + } virtual void on_paint(void) { c_rect rect; @@ -51,14 +56,8 @@ class c_myUI : public c_wnd tmp += 3; } } - GL_DECLARE_MESSAGE_MAP()//delcare message }; -//map message -GL_BEGIN_MESSAGE_MAP(c_myUI) -ON_GL_BN_CLICKED(c_myUI::on_clicked) -GL_END_MESSAGE_MAP() - //////////////////////// layout UI //////////////////////// static c_myUI s_myUI; static c_button s_button; diff --git a/HelloGuiLite/UIcode/GuiLite.h b/HelloGuiLite/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloGuiLite/UIcode/GuiLite.h +++ b/HelloGuiLite/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloGuiLite/UIcode/helloGL.cpp b/HelloGuiLite/UIcode/helloGL.cpp index 40a4fb100584ad0902f819bd11910faa16f724ab..d56f4dfd7cd35d90abf6deed2998688bd36af46d 100644 --- a/HelloGuiLite/UIcode/helloGL.cpp +++ b/HelloGuiLite/UIcode/helloGL.cpp @@ -42,50 +42,44 @@ class c_start_button : public c_button class c_desktop : public c_wnd { - virtual void on_paint(void); - void on_clicked(int ctrl_id, int param); - GL_DECLARE_MESSAGE_MAP()//delcare message -}; - -//map message -GL_BEGIN_MESSAGE_MAP(c_desktop) -ON_GL_BN_CLICKED(c_desktop::on_clicked) -GL_END_MESSAGE_MAP() - -void c_desktop::on_clicked(int ctrl_id, int param) -{ - static bool is_open = false; - (is_open) ? c_dialog::close_dialog(m_surface): c_dialog::open_dialog((c_dialog*)get_wnd_ptr(ID_START_MENU), false); - is_open = !is_open; -} - -void c_desktop::on_paint() -{ - c_rect rect; - get_screen_rect(rect); - extern const BITMAP_INFO desktop_bmp; - int block_width = 80; - int block_height = 60; - int block_rows = desktop_bmp.height / block_height; - int block_cols = desktop_bmp.width / block_width; - int block_sum = block_rows * block_cols; - bool* block_map = (bool*)calloc(block_sum, sizeof(bool)); - if (!block_map) { return; } - int sum = 0; - while (sum < block_sum) + virtual void on_init_children() + { + ((c_button*)get_wnd_ptr(ID_START_BUTTON))->set_on_click((WND_CALLBACK)&c_desktop::on_clicked); + } + virtual void on_paint(void) { - int x = rand() % block_cols; - int y = rand() % block_rows; - if (block_map[x + (y * block_cols)] == false) + c_rect rect; + get_screen_rect(rect); + extern const BITMAP_INFO desktop_bmp; + int block_width = 80; + int block_height = 60; + int block_rows = desktop_bmp.height / block_height; + int block_cols = desktop_bmp.width / block_width; + int block_sum = block_rows * block_cols; + bool* block_map = (bool*)calloc(block_sum, sizeof(bool)); + if (!block_map) { return; } + int sum = 0; + while (sum < block_sum) { - c_bitmap::draw_bitmap(m_surface, m_z_order, &desktop_bmp, rect.m_left + x * block_width, rect.m_top + y * block_height, x * block_width, y * block_height, block_width, block_height); - block_map[x + (y * block_cols)] = true; - sum++; - thread_sleep(10); + int x = rand() % block_cols; + int y = rand() % block_rows; + if (block_map[x + (y * block_cols)] == false) + { + c_bitmap::draw_bitmap(m_surface, m_z_order, &desktop_bmp, rect.m_left + x * block_width, rect.m_top + y * block_height, x * block_width, y * block_height, block_width, block_height); + block_map[x + (y * block_cols)] = true; + sum++; + thread_sleep(10); + } } + free(block_map); } - free(block_map); -} + void on_clicked(int ctrl_id, int param) + { + static bool is_open = false; + (is_open) ? c_dialog::close_dialog(m_surface) : c_dialog::open_dialog((c_dialog*)get_wnd_ptr(ID_START_MENU), false); + is_open = !is_open; + } +}; class c_start_menu : public c_dialog { diff --git a/HelloLayers/UIcode/GuiLite.h b/HelloLayers/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloLayers/UIcode/GuiLite.h +++ b/HelloLayers/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloMario/UIcode/GuiLite.h b/HelloMario/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloMario/UIcode/GuiLite.h +++ b/HelloMario/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloMolecule/UIcode/GuiLite.h b/HelloMolecule/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloMolecule/UIcode/GuiLite.h +++ b/HelloMolecule/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloNets/UIcode/GuiLite.h b/HelloNets/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloNets/UIcode/GuiLite.h +++ b/HelloNets/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloNoTouch/UIcode/GuiLite.h b/HelloNoTouch/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloNoTouch/UIcode/GuiLite.h +++ b/HelloNoTouch/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloNoTouch/UIcode/UIcode.cpp b/HelloNoTouch/UIcode/UIcode.cpp index 8fda5dab94fff4ca0e0426b693903d25c0239ae2..a117ced15070dfbdd41af54a5cf2abcf56d7d758 100644 --- a/HelloNoTouch/UIcode/UIcode.cpp +++ b/HelloNoTouch/UIcode/UIcode.cpp @@ -20,6 +20,12 @@ enum WND_ID class c_myUI : public c_wnd { + virtual void on_init_children() + { + ((c_button*)get_wnd_ptr(ID_BUTTON1))->set_on_click((WND_CALLBACK)&c_myUI::on_clicked); + ((c_button*)get_wnd_ptr(ID_BUTTON2))->set_on_click((WND_CALLBACK)&c_myUI::on_clicked); + ((c_button*)get_wnd_ptr(ID_BUTTON3))->set_on_click((WND_CALLBACK)&c_myUI::on_clicked); + } virtual void on_paint(void) { c_rect rect; @@ -47,14 +53,8 @@ class c_myUI : public c_wnd } button->show_window(); } - GL_DECLARE_MESSAGE_MAP()//delcare message }; -//map message -GL_BEGIN_MESSAGE_MAP(c_myUI) -ON_GL_BN_CLICKED(c_myUI::on_clicked) -GL_END_MESSAGE_MAP() - //////////////////////// layout UI //////////////////////// static c_myUI s_myUI; static c_label s_label1, s_label2, s_label3; diff --git a/HelloParticle/UIcode/GuiLite.h b/HelloParticle/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloParticle/UIcode/GuiLite.h +++ b/HelloParticle/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloPendulum/UIcode/GuiLite.h b/HelloPendulum/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloPendulum/UIcode/GuiLite.h +++ b/HelloPendulum/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloScroll/UIcode/GuiLite.h b/HelloScroll/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloScroll/UIcode/GuiLite.h +++ b/HelloScroll/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloScroll/UIcode/UIcode.cpp b/HelloScroll/UIcode/UIcode.cpp index d3d6f954d31d2952dc393bdecb76c09a6ea501df..8053073cdd63aa174894e0a60b2290c9ef981a14 100644 --- a/HelloScroll/UIcode/UIcode.cpp +++ b/HelloScroll/UIcode/UIcode.cpp @@ -27,11 +27,25 @@ enum WND_ID extern const BITMAP_INFO image1_bmp, image2_bmp, image3_bmp, image4_bmp, image5_bmp, image6_bmp, image7_bmp, image8_bmp, image9_bmp; -class c_my_ui : public c_wnd +class c_scroll_view_v : public c_scroll_view { + virtual void on_init_children() + { + ((c_button*)get_wnd_ptr(ID_BUTTON_1))->set_on_click((WND_CALLBACK)&c_scroll_view_v::on_button_clicked); + ((c_button*)get_wnd_ptr(ID_BUTTON_2))->set_on_click((WND_CALLBACK)&c_scroll_view_v::on_button_clicked); + ((c_button*)get_wnd_ptr(ID_BUTTON_3))->set_on_click((WND_CALLBACK)&c_scroll_view_v::on_button_clicked); + ((c_button*)get_wnd_ptr(ID_BUTTON_4))->set_on_click((WND_CALLBACK)&c_scroll_view_v::on_button_clicked); + ((c_button*)get_wnd_ptr(ID_BUTTON_5))->set_on_click((WND_CALLBACK)&c_scroll_view_v::on_button_clicked); + ((c_button*)get_wnd_ptr(ID_BUTTON_6))->set_on_click((WND_CALLBACK)&c_scroll_view_v::on_button_clicked); + ((c_button*)get_wnd_ptr(ID_BUTTON_7))->set_on_click((WND_CALLBACK)&c_scroll_view_v::on_button_clicked); + ((c_button*)get_wnd_ptr(ID_BUTTON_8))->set_on_click((WND_CALLBACK)&c_scroll_view_v::on_button_clicked); + ((c_button*)get_wnd_ptr(ID_BUTTON_9))->set_on_click((WND_CALLBACK)&c_scroll_view_v::on_button_clicked); + + c_scroll_view::on_init_children(); + } void on_button_clicked(int ctrl_id, int param) { - switch (param) + switch (ctrl_id) { case ID_BUTTON_1: c_bitmap::draw_bitmap(m_surface, m_z_order, &image1_bmp, 230, 10); @@ -65,16 +79,12 @@ class c_my_ui : public c_wnd break; } } - GL_DECLARE_MESSAGE_MAP()//delcare message }; -GL_BEGIN_MESSAGE_MAP(c_my_ui) -ON_GL_BN_CLICKED(c_my_ui::on_button_clicked) -GL_END_MESSAGE_MAP() - // Layout Widgets -static c_my_ui s_my_ui; -static c_scroll_view s_scroll_view_1, s_scroll_view_2; +static c_wnd s_my_ui; +static c_scroll_view_v s_scroll_view_1; +static c_scroll_view s_scroll_view_2; static c_button s_button_1, s_button_2, s_button_3, s_button_4, s_button_5, s_button_6, s_button_7, s_button_8, s_button_9; static c_label label_1; @@ -102,7 +112,7 @@ WND_TREE s_scroll_widgets_2[] = WND_TREE s_main_widgets[] = { - {(c_wnd*)&s_scroll_view_1, ID_SCROLL_VIEW_1, 0, 0, 0, 220, 290, s_scroll_widgets_1}, + {(c_wnd*)&s_scroll_view_1, ID_SCROLL_VIEW_1, 0, 0, 0, 600, 290, s_scroll_widgets_1}, {(c_wnd*)&s_scroll_view_2, ID_SCROLL_VIEW_2, 0, 0, 300, 600, 100, s_scroll_widgets_2}, {NULL, 0 , 0, 0, 0, 0, 0} }; diff --git a/HelloScroll/UIcode/scroll.h b/HelloScroll/UIcode/scroll.h index 6699286ab0e50bc2d364ed51d3fefcf846db4152..2c818d274176567db7469ca37cda7703bc5ff363 100644 --- a/HelloScroll/UIcode/scroll.h +++ b/HelloScroll/UIcode/scroll.h @@ -20,8 +20,9 @@ public: }; #define MOVE_THRESHOLD 10 -class c_scroll_view : c_wnd +class c_scroll_view : public c_wnd { +protected: virtual void pre_create_wnd() { m_bg_color = GL_RGB(220, 220, 220); @@ -154,12 +155,6 @@ class c_scroll_view : c_wnd } } } - void on_button_clicked(int ctrl_id, int param) - { - notify_parent(GL_BN_CLICKED, ctrl_id); - } - - GL_DECLARE_MESSAGE_MAP()//delcare message private: TOUCH_ACTION m_touch_action = TOUCH_UP; c_display* m_mem_display; @@ -169,9 +164,3 @@ private: int m_offset_y = 0; int m_down_x, m_down_y; }; - -#ifdef GUILITE_ON -GL_BEGIN_MESSAGE_MAP(c_scroll_view) -ON_GL_BN_CLICKED(c_scroll_view::on_button_clicked) -GL_END_MESSAGE_MAP() -#endif diff --git a/HelloSlide/UIcode/GuiLite.h b/HelloSlide/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloSlide/UIcode/GuiLite.h +++ b/HelloSlide/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloStar/UIcode/GuiLite.h b/HelloStar/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloStar/UIcode/GuiLite.h +++ b/HelloStar/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloTimer/UIcode/GuiLite.h b/HelloTimer/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloTimer/UIcode/GuiLite.h +++ b/HelloTimer/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloTransparent/UIcode/GuiLite.h b/HelloTransparent/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloTransparent/UIcode/GuiLite.h +++ b/HelloTransparent/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloTransparent/UIcode/UIcode.cpp b/HelloTransparent/UIcode/UIcode.cpp index 20ce977962ef569276fe2612c2433a02a64155c6..b72187be4f7fdb1c3908d3c7a1bd1151fb844aec 100644 --- a/HelloTransparent/UIcode/UIcode.cpp +++ b/HelloTransparent/UIcode/UIcode.cpp @@ -50,6 +50,10 @@ class c_wave : public c_wave_ctrl class c_my_dialog : public c_dialog { + virtual void on_init_children() + { + ((c_button*)get_wnd_ptr(ID_BUTTON))->set_on_click((WND_CALLBACK)&c_my_dialog::on_clicked); + } virtual void on_paint(void) { c_rect rect; @@ -61,15 +65,8 @@ class c_my_dialog : public c_dialog c_dialog::close_dialog(m_surface); ((c_surface_transparent*)m_surface)->clear_layer(m_z_order); } - - GL_DECLARE_MESSAGE_MAP()//delcare message }; -//map message -GL_BEGIN_MESSAGE_MAP(c_my_dialog) -ON_GL_BN_CLICKED(c_my_dialog::on_clicked) -GL_END_MESSAGE_MAP() - class c_my_ui : public c_wnd { public: diff --git a/HelloWave/UIcode/GuiLite.h b/HelloWave/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloWave/UIcode/GuiLite.h +++ b/HelloWave/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloWave/UIcode/UIcode.cpp b/HelloWave/UIcode/UIcode.cpp index 89c2b0369ebb1cca0a0647d5161beba093596749..681e418f8868d499924be507406578fb8e788bd1 100644 --- a/HelloWave/UIcode/UIcode.cpp +++ b/HelloWave/UIcode/UIcode.cpp @@ -46,6 +46,8 @@ enum WND_ID class c_myUI : public c_wnd { virtual void on_init_children(void) { + ((c_button*)get_wnd_ptr(ID_BUTTON))->set_on_click((WND_CALLBACK)&c_myUI::on_clicked); + c_wave_ctrl *p_wave = (c_wave_ctrl*)get_wnd_ptr(ID_WAVE1); p_wave->set_wave_speed(1); p_wave->set_wave_color(GL_RGB(0, 255, 0)); @@ -96,14 +98,8 @@ public: c_wave_buffer m_wave_buffer1; c_wave_buffer m_wave_buffer2; c_wave_buffer m_wave_buffer3; - GL_DECLARE_MESSAGE_MAP()//delcare message }; -//map message -GL_BEGIN_MESSAGE_MAP(c_myUI) -ON_GL_BN_CLICKED(c_myUI::on_clicked) -GL_END_MESSAGE_MAP() - //////////////////////// layout UI //////////////////////// static c_myUI s_myUI; static c_wave_ctrl s_wave1; diff --git a/HelloWidgets/UIcode/GuiLite.h b/HelloWidgets/UIcode/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HelloWidgets/UIcode/GuiLite.h +++ b/HelloWidgets/UIcode/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HelloWidgets/UIcode/UIcode.cpp b/HelloWidgets/UIcode/UIcode.cpp index 5a743446f740ffb5eed02523f2d8c8d2711e2cc7..e48aa75cc0ab2ce5d93b3952abaff4049578a278 100644 --- a/HelloWidgets/UIcode/UIcode.cpp +++ b/HelloWidgets/UIcode/UIcode.cpp @@ -27,6 +27,9 @@ class c_my_ui : public c_wnd { virtual void on_init_children() { + c_button* button = (c_button*)get_wnd_ptr(ID_BUTTON); + button->set_on_click((WND_CALLBACK)&c_my_ui::on_button_clicked); + c_edit* edit = (c_edit*)get_wnd_ptr(ID_EDIT_1); edit->set_keyboard_style(STYLE_ALL_BOARD); @@ -34,6 +37,7 @@ class c_my_ui : public c_wnd edit->set_keyboard_style(STYLE_NUM_BOARD); c_list_box *list_box = (c_list_box*)get_wnd_ptr(ID_LIST_BOX); + list_box->set_on_change((WND_CALLBACK)&c_my_ui::on_listbox_confirm); list_box->clear_item(); list_box->add_item((char*)"Item 0"); list_box->add_item((char*)"Item 1"); @@ -41,6 +45,7 @@ class c_my_ui : public c_wnd list_box->select_item(0); c_spin_box *spin_box = (c_spin_box*)get_wnd_ptr(ID_SPIN_BOX); + spin_box->set_on_change((WND_CALLBACK)&c_my_ui::on_spinbox_change); spin_box->set_max_min(9, 0); spin_box->set_step(1); spin_box->set_value(5); @@ -78,17 +83,16 @@ class c_my_ui : public c_wnd label->set_str(str); label->show_window(); } - GL_DECLARE_MESSAGE_MAP()//delcare message }; -GL_BEGIN_MESSAGE_MAP(c_my_ui) -ON_GL_BN_CLICKED(c_my_ui::on_button_clicked) -ON_SPIN_CHANGE(c_my_ui::on_spinbox_change) -ON_LIST_CONFIRM(c_my_ui::on_listbox_confirm) -GL_END_MESSAGE_MAP() - class c_my_dialog : public c_dialog { + virtual void on_init_children() + { + c_button* button = (c_button*)get_wnd_ptr(ID_DIALOG_EXIT_BUTTON); + button->set_on_click((WND_CALLBACK)&c_my_dialog::on_button_clicked); + } + void on_button_clicked(int ctrl_id, int param) { switch (ctrl_id) @@ -100,13 +104,8 @@ class c_my_dialog : public c_dialog break; } } - GL_DECLARE_MESSAGE_MAP()//delcare message }; -GL_BEGIN_MESSAGE_MAP(c_my_dialog) -ON_GL_BN_CLICKED(c_my_dialog::on_button_clicked) -GL_END_MESSAGE_MAP() - // Layout Widgets static c_my_ui s_my_ui; static c_label s_label_1, s_label_2, s_label_3; diff --git a/HostMonitor/UIcode/include/GuiLite.h b/HostMonitor/UIcode/include/GuiLite.h index 4df4afa0b2f9f38b14ed04e3d30b83d8597dfe84..e397552be25d13e069dc7a89d75b1bb35f95a356 100644 --- a/HostMonitor/UIcode/include/GuiLite.h +++ b/HostMonitor/UIcode/include/GuiLite.h @@ -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); @@ -102,123 +102,6 @@ public: int m_right; int m_bottom; }; -#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() -}; //BITMAP typedef struct struct_bitmap_info { @@ -1329,9 +1212,9 @@ typedef struct struct_wnd_tree short height; 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) {}; @@ -1370,7 +1253,6 @@ public: } if (load_child_wnd(p_child_tree) >= 0) { - load_cmd_msg(); on_init_children(); } return 0; @@ -1549,19 +1431,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; @@ -1733,6 +1602,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. @@ -1740,23 +1610,18 @@ 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); }; -#define GL_BN_CLICKED 0x1111 -#define ON_GL_BN_CLICKED(func) {MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)}, -typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { +public: + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void on_paint() { @@ -1803,6 +1668,7 @@ protected: } virtual void pre_create_wnd() { + on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); @@ -1819,7 +1685,10 @@ protected: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_BN_CLICKED, 0); + if(on_click) + { + (m_parent->*(on_click))(m_id, 0); + } } } virtual void on_navigate(NAVIGATION_KEY key) @@ -1836,6 +1705,7 @@ protected: } return c_wnd::on_navigate(key); } + WND_CALLBACK on_click; }; class c_surface; class c_dialog; @@ -2006,8 +1876,21 @@ public: } return -1; } + virtual void on_init_children() + { + c_wnd* child = m_top_child; + if (0 != child) + { + while (child) + { + ((c_button*)child)->set_on_click(WND_CALLBACK(&c_keyboard::on_key_clicked)); + child = child->get_next_sibling(); + } + } + } KEYBOARD_STATUS get_cap_status(){return m_cap_status;} char* get_str() { return m_str; } + void set_on_click(WND_CALLBACK on_click) { this->on_click = on_click; } protected: virtual void pre_create_wnd() { @@ -2064,7 +1947,7 @@ protected: ASSERT(false); InputChar: m_str[m_str_len++] = id; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_del_clicked(int id, int param) { @@ -2073,7 +1956,7 @@ protected: return; } m_str[--m_str_len] = 0; - notify_parent(KEYBORAD_CLICK, CLICK_CHAR); + (m_parent->*(on_click))(m_id, CLICK_CHAR); } void on_caps_clicked(int id, int param) { @@ -2083,18 +1966,18 @@ protected: void on_enter_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - return notify_parent(KEYBORAD_CLICK, CLICK_ENTER); + (m_parent->*(on_click))(m_id, CLICK_ENTER); } void on_esc_clicked(int id, int param) { memset(m_str, 0, sizeof(m_str)); - notify_parent(KEYBORAD_CLICK, CLICK_ESC); + (m_parent->*(on_click))(m_id, CLICK_ESC); } - GL_DECLARE_MESSAGE_MAP() private: char m_str[32]; int m_str_len; KEYBOARD_STATUS m_cap_status; + WND_CALLBACK on_click; }; class c_keyboard_button : public c_button { @@ -2284,11 +2167,11 @@ protected: break; } } - GL_DECLARE_MESSAGE_MAP() private: void show_keyboard() { s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style); + s_keyboard.set_on_click(WND_CALLBACK(&c_edit::on_key_board_click)); s_keyboard.show_window(); } void on_touch_down(int x, int y) @@ -2368,12 +2251,12 @@ protected: }; #include #define MAX_ITEM_NUM 4 -#define GL_LIST_CONFIRM 0x1 #define ITEM_HEIGHT 45 -#define ON_LIST_CONFIRM(func) {MSG_TYPE_WND, GL_LIST_CONFIRM, 0, msgCallback(&func)}, class c_list_box : public c_wnd { public: + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } + short get_item_count() { return m_item_total; } int add_item(char* str) { if (m_item_total >= MAX_ITEM_NUM) @@ -2391,7 +2274,6 @@ public: memset(m_item_array, 0, sizeof(m_item_array)); update_list_size(); } - short get_item_count() { return m_item_total; } void select_item(short index) { if (index < 0 || index >= m_item_total) @@ -2546,7 +2428,10 @@ private: { m_status = STATUS_FOCUSED; on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } } } @@ -2569,7 +2454,10 @@ private: m_status = STATUS_FOCUSED; select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT); on_paint(); - notify_parent(GL_LIST_CONFIRM, m_selected_item); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_selected_item); + } } else { @@ -2582,6 +2470,7 @@ private: char* m_item_array[MAX_ITEM_NUM]; c_rect m_list_wnd_rect; //rect relative to parent wnd. c_rect m_list_screen_rect; //rect relative to physical screen(frame buffer) + WND_CALLBACK on_change; }; #include #define MAX_PAGES 5 @@ -2920,8 +2809,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) } #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 -#define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CHANGE(func) {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, class c_spin_box; class c_spin_button : public c_button { @@ -2942,6 +2829,7 @@ public: short get_step() { return m_step; } void set_value_digit(short digit) { m_digit = digit; } short get_value_digit() { return m_digit; } + void set_on_change(WND_CALLBACK on_change) { this->on_change = on_change; } protected: virtual void on_paint() { @@ -2974,7 +2862,10 @@ protected: return; } m_cur_value += m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } void on_arrow_down_bt_click() @@ -2984,7 +2875,10 @@ protected: return; } m_cur_value -= m_step; - notify_parent(GL_SPIN_CHANGE, m_cur_value); + if(on_change) + { + (m_parent->*(on_change))(m_id, m_cur_value); + } on_paint(); } short m_cur_value; @@ -2995,6 +2889,7 @@ protected: short m_digit; c_spin_button m_bt_up; c_spin_button m_bt_down; + WND_CALLBACK on_change; }; inline void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) { @@ -3451,12 +3346,6 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; -#ifdef GUILITE_ON -GL_MSG_ENTRY c_cmd_target::ms_usr_map_entries[USR_MSG_MAX]; -unsigned short c_cmd_target::ms_user_map_size; -GL_BEGIN_MESSAGE_MAP(c_cmd_target) -GL_END_MESSAGE_MAP() -#endif #ifdef GUILITE_ON @@ -3521,7 +3410,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -3542,7 +3432,7 @@ static void* timer_routine(void*) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } usleep(1000 * TIMER_UNIT); @@ -3562,7 +3452,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc)(void* param), void* param) { init_mul_timer(); int i; @@ -3578,6 +3468,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -3641,9 +3532,9 @@ unsigned int get_cur_thread_id() { return (unsigned long)pthread_self(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4002,7 +3893,8 @@ typedef struct _timer_manage int state; /* on or off */ int interval; int elapse; /* 0~interval */ - void (* timer_proc) (void* ptmr, void* parg); + void (* timer_proc) (void* param); + void* param; }timer_info[MAX_TIMER_CNT]; void (* old_sigfunc)(int); void (* new_sigfunc)(int); @@ -4023,7 +3915,7 @@ DWORD WINAPI timer_routine(LPVOID lpParam) if(timer_manage.timer_info[i].elapse == timer_manage.timer_info[i].interval) { timer_manage.timer_info[i].elapse = 0; - timer_manage.timer_info[i].timer_proc(0, 0); + timer_manage.timer_info[i].timer_proc(timer_manage.timer_info[i].param); } } Sleep(TIMER_UNIT); @@ -4043,7 +3935,7 @@ static int init_mul_timer() s_is_init = true; return 1; } -static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg)) +static int set_a_timer(int interval, void (* timer_proc) (void* param), void* param) { init_mul_timer(); int i; @@ -4059,6 +3951,7 @@ static int set_a_timer(int interval, void (* timer_proc) (void* ptmr, void* parg } memset(&timer_manage.timer_info[i], 0, sizeof(timer_manage.timer_info[i])); timer_manage.timer_info[i].timer_proc = timer_proc; + timer_manage.timer_info[i].param = param; timer_manage.timer_info[i].interval = interval; timer_manage.timer_info[i].elapse = 0; timer_manage.timer_info[i].state = 1; @@ -4126,9 +4019,9 @@ unsigned int get_cur_thread_id() { return GetCurrentThreadId(); } -void register_timer(int milli_second,void func(void* ptmr, void* parg)) +void register_timer(int milli_second,void func(void* param), void* param) { - set_a_timer(milli_second/TIMER_UNIT,func); + set_a_timer(milli_second/TIMER_UNIT,func, param); } long get_time_in_second() { @@ -4305,9 +4198,6 @@ DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX]; #endif #ifdef GUILITE_ON c_keyboard c_edit::s_keyboard; -GL_BEGIN_MESSAGE_MAP(c_edit) -ON_KEYBORAD_UPDATE(c_edit::on_key_board_click) -GL_END_MESSAGE_MAP() #endif #ifdef GUILITE_ON static c_keyboard_button s_key_0, s_key_1, s_key_2, s_key_3, s_key_4, s_key_5, s_key_6, s_key_7, s_key_8, s_key_9; @@ -4375,7 +4265,4 @@ WND_TREE g_number_board_children[] = {&s_key_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2}, {0,0,0,0,0,0,0} }; -GL_BEGIN_MESSAGE_MAP(c_keyboard) -ON_GL_BN_CLICKED(c_keyboard::on_key_clicked) -GL_END_MESSAGE_MAP() #endif diff --git a/HostMonitor/UIcode/include/ctrl_id.h b/HostMonitor/UIcode/include/ctrl_id.h index 6d77588b62026c4d78c99ede44a2c337eb96bf65..c57141983b0496cac636bf8c90e92b6397e31033 100644 --- a/HostMonitor/UIcode/include/ctrl_id.h +++ b/HostMonitor/UIcode/include/ctrl_id.h @@ -106,7 +106,9 @@ typedef enum e_ctrlid * dialog ****************************************/ //patient setup dialog - IDD_SETUP_DLG, + ID_SETUP_BUTTON, + ID_ABOUT_BUTTON, + ID_SETUP_DLG, ID_SETUP_DLG_EDIT_FIRST_NAME, ID_SETUP_DLG_EDIT_SECOND_NAME, ID_SETUP_DLG_LB_PATIENT_TYPE, diff --git a/HostMonitor/UIcode/include/msg_id.h b/HostMonitor/UIcode/include/msg_id.h deleted file mode 100644 index 21399995dbb267f15eef7f6c56722c3687b2a98a..0000000000000000000000000000000000000000 --- a/HostMonitor/UIcode/include/msg_id.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _KEY_MSG_H -#define _KEY_MSG_H - -typedef struct -{ - unsigned int dwMsgId; - unsigned int dwParam1; - unsigned int dwParam2; -}MSG_INFO; - -typedef enum e_app_msg -{ - USR_MSG_UPDATE_TIME = 0x5300, - USR_MSG_UPDATE_TREND_VIEW -}E_APP_MSG; - -#endif diff --git a/HostMonitor/UIcode/source/manager/wave_manager.h b/HostMonitor/UIcode/source/manager/wave_manager.h index 33d79c29df05dfda16751105c305e08590611adc..4e3c2e06cd2ddd49582b038f240a3abf1caea38c 100644 --- a/HostMonitor/UIcode/source/manager/wave_manager.h +++ b/HostMonitor/UIcode/source/manager/wave_manager.h @@ -44,7 +44,7 @@ typedef struct struct_wave_ctrl_discpritor }WAVE_CTRL_DISCPRITOR; class c_wave_ctrl; -class c_wave_manage : public c_cmd_target +class c_wave_manage { public: int register_wave_ctrl(WAVE_TYPE wave_ctrl_type, c_wave_ctrl* p_wave); @@ -59,11 +59,7 @@ public: private: c_wave_buffer m_waves[WAVE_TYPE_MAX]; c_wave_ctrl* m_wave_ctrls[WAVE_TYPE_MAX][WAVE_CTRL_MAX]; - c_wave_manage(); - c_wave_manage(const c_wave_manage&); - c_wave_manage& operator=(const c_wave_manage&); - ~c_wave_manage(){} }; #endif diff --git a/HostMonitor/UIcode/source/modules/demo_module.cpp b/HostMonitor/UIcode/source/modules/demo_module.cpp index 17ce2327586c8edc3dffe3187d74bffe70e90652..dca92a88aa35082a02491aaf1f108ff66601f48e 100644 --- a/HostMonitor/UIcode/source/modules/demo_module.cpp +++ b/HostMonitor/UIcode/source/modules/demo_module.cpp @@ -1,4 +1,3 @@ -#include "../include/msg_id.h" #include "../source/manager/wave_manager.h" #include "../source/manager/value_manager.h" #include diff --git a/HostMonitor/UIcode/source/start/host_monitor.cpp b/HostMonitor/UIcode/source/start/host_monitor.cpp index 642748354225e687e432dbd67f3d42e76826ae32..2188a717fd6b1186f73bdd000cceb1d375a19537 100644 --- a/HostMonitor/UIcode/source/start/host_monitor.cpp +++ b/HostMonitor/UIcode/source/start/host_monitor.cpp @@ -1,6 +1,4 @@ #define GUILITE_ON //Do not define this macro once more!!! -#include "../include/msg_id.h" -#include "../manager/value_manager.h" #include "../manager/wave_manager.h" #include "../modules/module_group.h" #include "../data/database.h" @@ -8,49 +6,9 @@ #include #include +extern void load_theme(int index); extern void load_ui_single(void* phy_fb, int width, int height, int color_bytes); -static void init(); -static void wave_refresh_timer_callback(void* arg); -static void database_timer_callback(void* ptmr, void* parg); - -static c_fifo s_usr_fifo; -int read_usr_msg(MSG_INFO* msg) -{ - return s_usr_fifo.read(msg, sizeof(MSG_INFO)); -} -int write_usr_msg(MSG_INFO* msg) -{ - if (msg->dwMsgId & 0xf000000)ASSERT(false); - return s_usr_fifo.write(msg, sizeof(MSG_INFO)); -} - -void startHostMonitor(void* phy_fb, int screen_width, int screen_height, int color_bytes) -{ - init(); - - //Load UI. - load_ui_single(phy_fb, screen_width, screen_height, color_bytes); - - //Start system. - start_real_timer(wave_refresh_timer_callback); - register_timer((60 * 1000), database_timer_callback);//update data per minute. - - MSG_INFO msg; - msg.dwMsgId = USR_MSG_UPDATE_TREND_VIEW; - write_usr_msg(&msg); - - while(1) - { - if (read_usr_msg(&msg) > 0) - { - ASSERT((msg.dwMsgId & 0xf0000000) == 0); - c_cmd_target::handle_usr_msg(msg.dwMsgId, msg.dwParam1, msg.dwParam2); - } - } -} - -extern void load_theme(int index); static void init() { c_database::get_instance()->init(); @@ -63,29 +21,11 @@ static void wave_refresh_timer_callback(void* arg) c_wave_manage::get_instance()->refurbish_all_waves(); } -typedef int(*SYNC_DATA)(int hr, int spo2, int rr, int nibp_sys, int nibp_dia, int nibp_mean); -extern SYNC_DATA gSyncData; -static void database_timer_callback(void* ptmr, void* parg) +void startHostMonitor(void* phy_fb, int screen_width, int screen_height, int color_bytes) { - VALUE_SET data; - memset(&data, 0, sizeof(data)); - c_value_manager* real_data_mgr = c_value_manager::get_instance(); - - data.time = get_time_in_second(); - data.hr = data.pr = real_data_mgr->get_value(VALUE_HR); - data.spo2 = real_data_mgr->get_value(VALUE_SPO2); - data.rr = real_data_mgr->get_value(VALUE_RESP); - data.nibp_sys = real_data_mgr->get_value(VALUE_NIBP_SYS); - data.nibp_dia = real_data_mgr->get_value(VALUE_NIBP_DIA); - data.nibp_mean = real_data_mgr->get_value(VALUE_NIBP_MEAN); - c_database::get_instance()->write(data); - - MSG_INFO msg; - msg.dwMsgId = USR_MSG_UPDATE_TREND_VIEW; - write_usr_msg(&msg); - - if(gSyncData) - { - gSyncData(data.hr, data.spo2, data.rr, data.nibp_sys, data.nibp_dia, data.nibp_mean); - } + init(); + //Load UI. + load_ui_single(phy_fb, screen_width, screen_height, color_bytes); + //Start system. + start_real_timer(wave_refresh_timer_callback); } diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.cpp b/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.cpp index 9553dc6e53f27084c9edd3e04af9f70a191a72ca..4edc2f8bf72f7314b7780b62b6187b9b4c08a23a 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.cpp +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.cpp @@ -15,10 +15,6 @@ #define ID_FORWARD_BTN 3 #define ID_FAST_FORWARD_BTN 4 -GL_BEGIN_MESSAGE_MAP(c_time_bar) -ON_GL_BN_CLICKED(c_time_bar::on_btn_click) -GL_END_MESSAGE_MAP() - void c_time_bar::on_init_children() { set_time(get_time_in_second()); @@ -30,6 +26,11 @@ void c_time_bar::on_init_children() m_backward.connect(this, ID_BACKWARD_BTN, "<", (BUTTON_LENGTH + 1), 0, BUTTON_LENGTH, rect.height()); m_forward.connect(this, ID_FORWARD_BTN, ">", (rect.width() - 2 * BUTTON_LENGTH - 6), 0, BUTTON_LENGTH, rect.height()); m_fast_forward.connect(this, ID_FAST_FORWARD_BTN, ">>", (rect.width() - BUTTON_LENGTH - 5), 0, BUTTON_LENGTH, rect.height()); + + ((c_button*)get_wnd_ptr(ID_FAST_BACKWARD_BTN))->set_on_click((WND_CALLBACK)&c_time_bar::on_btn_click); + ((c_button*)get_wnd_ptr(ID_BACKWARD_BTN))->set_on_click((WND_CALLBACK)&c_time_bar::on_btn_click); + ((c_button*)get_wnd_ptr(ID_FORWARD_BTN))->set_on_click((WND_CALLBACK)&c_time_bar::on_btn_click); + ((c_button*)get_wnd_ptr(ID_FAST_FORWARD_BTN))->set_on_click((WND_CALLBACK)&c_time_bar::on_btn_click); } void c_time_bar::on_paint(void) @@ -168,5 +169,4 @@ void c_time_bar::on_btn_click(int ctrl_id, int param) m_end_seconds += increment; m_start_seconds += increment; draw_mark(); - notify_parent(ND_SCALE_CLICKED, 0); } diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.h b/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.h index fdd65ce8694bc2b8d66033b74470f94ab72f65f6..0c0d3fccb430da7ca9926bb604f68365445b7bd1 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.h +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.h @@ -3,11 +3,6 @@ #include "GuiLite.h" -#define ND_SCALE_CLICKED 0x2013 - -#define ON_ND_SACLE_CLICKED(func) \ -{MSG_TYPE_WND, ND_SCALE_CLICKED, 0, msgCallback(&func)}, - class c_time_bar : public c_wnd { public: @@ -34,7 +29,6 @@ private: c_button m_fast_backward; c_button m_forward; c_button m_fast_forward; - GL_DECLARE_MESSAGE_MAP() }; #endif diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/value_view.cpp b/HostMonitor/UIcode/source/ui_ctrl_ex/value_view.cpp index 9a79e036868db711696495210d8866964226e9aa..3de11913e11fe1bee66ee5e39b3a7f8f0d170b35 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/value_view.cpp +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/value_view.cpp @@ -47,13 +47,13 @@ int c_value_view::register_value_view(c_value_view* p_pm_view) if (!ms_is_has_timer) { - register_timer(1000, c_value_view::refresh_group_value); + register_timer(1000, c_value_view::refresh_group_value, 0); ms_is_has_timer = true; } return 1; } -void c_value_view::refresh_group_value(void* ptmr, void* parg) +void c_value_view::refresh_group_value(void* param) { static unsigned int s_sequnce; unsigned int flash_color = (s_sequnce++ % 2) ? GL_RGB(255, 0, 0) : GL_RGB(0, 0, 0); diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/value_view.h b/HostMonitor/UIcode/source/ui_ctrl_ex/value_view.h index 503329519209040d782f8a52fc8dfc2fb0d91510..a62a811a731f74258acfadfd69bc598378831d8f 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/value_view.h +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/value_view.h @@ -6,7 +6,7 @@ class c_value_view : public c_wnd { public: - static void refresh_group_value(void* ptmr, void* parg); + static void refresh_group_value(void* param); protected: static int register_value_view(c_value_view* p_pm_view); void refresh_value(bool flash_or_not, unsigned int flash_color); diff --git a/HostMonitor/UIcode/source/ui_layout/View/ecg_value/ecg_value_view.cpp b/HostMonitor/UIcode/source/ui_layout/View/ecg_value/ecg_value_view.cpp index 7eb0fe5d4b2adf59ea44135eaab71fc8d9be2f85..794568ed6e46866f7cb12a10dae993dbf5b3e948 100644 --- a/HostMonitor/UIcode/source/ui_layout/View/ecg_value/ecg_value_view.cpp +++ b/HostMonitor/UIcode/source/ui_layout/View/ecg_value/ecg_value_view.cpp @@ -1,6 +1,5 @@ #include "../include/GuiLite.h" #include "../include/ctrl_id.h" -#include "../include/msg_id.h" #include "../source/ui_ctrl_ex/value_view.h" #include "../source/ui_ctrl_ex/value_ctrl.h" diff --git a/HostMonitor/UIcode/source/ui_layout/View/top_bar/top_bar.cpp b/HostMonitor/UIcode/source/ui_layout/View/top_bar/top_bar.cpp index 7ea79b7d1110e38ef6e397187035885c9ea765f1..3479f01db9665d0bac0c8567de745d80201a9268 100644 --- a/HostMonitor/UIcode/source/ui_layout/View/top_bar/top_bar.cpp +++ b/HostMonitor/UIcode/source/ui_layout/View/top_bar/top_bar.cpp @@ -1,17 +1,12 @@ #include "../include/GuiLite.h" -#include "../include/msg_id.h" #include "../include/ctrl_id.h" #include "top_bar.h" #include "top_bar_xml.h" -GL_BEGIN_MESSAGE_MAP(c_top_bar) -ON_GL_USER_MSG(USR_MSG_UPDATE_TIME,c_top_bar::on_refurbish_time) -GL_END_MESSAGE_MAP() - void c_top_bar::on_init_children(void) { m_bg_color = GL_RGB(0,0,0); - register_timer(1000, c_top_bar::sysinfo_timer_callback); + register_timer(1000, c_top_bar::sysinfo_timer_callback, this); } void c_top_bar::on_paint(void) @@ -22,21 +17,8 @@ void c_top_bar::on_paint(void) m_surface->draw_hline(rect.m_left,rect.m_right,rect.m_bottom,GL_RGB(74,74,74), m_z_order); } -void c_top_bar::on_refurbish_time(int id, int param) -{ - c_wnd *p_ctl = get_wnd_ptr(ID_TOP_BAR_TIME_ID); - if(p_ctl == 0) - { - ASSERT(false); - return; - } - p_ctl->on_paint(); -} - -extern int write_usr_msg(MSG_INFO* msg); -void c_top_bar::sysinfo_timer_callback(void* ptmr, void* parg) +void c_top_bar::sysinfo_timer_callback(void* param)//tbd { - MSG_INFO msg_info; - msg_info.dwMsgId = USR_MSG_UPDATE_TIME; - write_usr_msg(&msg_info); + c_top_bar* top_bar = (c_top_bar*)param; + top_bar->get_wnd_ptr(ID_TOP_BAR_TIME_ID)->on_paint(); } diff --git a/HostMonitor/UIcode/source/ui_layout/View/top_bar/top_bar.h b/HostMonitor/UIcode/source/ui_layout/View/top_bar/top_bar.h index ee83ca32c3cdd1b234962c98e8594c03e391c0fe..c700a204c7b9fed31b88e8ce914dc1c8d2356ecd 100644 --- a/HostMonitor/UIcode/source/ui_layout/View/top_bar/top_bar.h +++ b/HostMonitor/UIcode/source/ui_layout/View/top_bar/top_bar.h @@ -4,12 +4,10 @@ class c_top_bar : public c_wnd { public: - static void sysinfo_timer_callback(void* ptmr, void* parg); + static void sysinfo_timer_callback(void* param); protected: virtual void on_init_children(void); virtual void on_paint(void); - void on_refurbish_time(int id, int param); - GL_DECLARE_MESSAGE_MAP() }; #endif diff --git a/HostMonitor/UIcode/source/ui_layout/View/trend/trend_view.cpp b/HostMonitor/UIcode/source/ui_layout/View/trend/trend_view.cpp index 9b56410bb56785974732d4e9025b62d055df6a1f..3fe047bc0b5d18c55fc995ba48b9467a0d1d3680 100644 --- a/HostMonitor/UIcode/source/ui_layout/View/trend/trend_view.cpp +++ b/HostMonitor/UIcode/source/ui_layout/View/trend/trend_view.cpp @@ -1,11 +1,10 @@ #include "../include/GuiLite.h" #include "../include/ctrl_id.h" -#include "../include/msg_id.h" +#include "../../../manager/value_manager.h" #include "../source/data/database.h" #include "../source/ui_ctrl_ex/trend_graph.h" #include "../source/ui_ctrl_ex/trend_table.h" #include "../source/ui_ctrl_ex/time_bar.h" -#include #include "trend_view.h" #define HR_COLOR GL_RGB(148,251,78) @@ -16,17 +15,13 @@ #define H_AXIS_MARK_CNT 7 #define H_AXIS_MARK_INTERVAL (60 * 10) //10 minutes between 2 marks -GL_BEGIN_MESSAGE_MAP(c_trend_view) -ON_ND_SACLE_CLICKED(c_trend_view::on_time_bar_change) -ON_GL_USER_MSG(USR_MSG_UPDATE_TREND_VIEW, c_trend_view::on_update_trend_view) -GL_END_MESSAGE_MAP() - void c_trend_view::on_init_children(void) { - c_trend_graph* p_trend_graph = (c_trend_graph*)get_wnd_ptr(ID_TREND_SCREEN_VITAL_TREND_CTRL); + c_trend_graph* p_trend_graph = (c_trend_graph*)get_wnd_ptr(ID_TREND_SCREEN_VITAL_TREND_CTRL); p_trend_graph->set_type(TREND_TYPE_VITAL); p_trend_graph = (c_trend_graph*)get_wnd_ptr(ID_TREND_SCREEN_PRESSURE_CTRL); p_trend_graph->set_type(TREND_TYPE_NIBP); + register_timer((60 * 1000), database_timer_callback, this); } void c_trend_view::on_paint(void) @@ -38,21 +33,21 @@ void c_trend_view::on_paint(void) m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right-2, rect.m_bottom-7, GL_RGB(165,166,156), m_z_order); m_surface->draw_rect(rect.m_left+1, rect.m_top+1, rect.m_right-3, rect.m_bottom-8, GL_RGB(123,125,123), m_z_order); m_surface->draw_rect(rect.m_left+2, rect.m_top+2, rect.m_right-4, rect.m_bottom-9, GL_RGB(99,101,99), m_z_order); -} -void c_trend_view::on_time_bar_change(int ctrl_id, int param) -{ - c_time_bar* p_time_bar = (c_time_bar*)get_wnd_ptr(ID_TREND_SCREEN_TIME_SCALE_BAR_CTRL); - refresh_trend_table(p_time_bar->get_start_time(), p_time_bar->get_end_time()); - refresh_trend_graphic(p_time_bar->get_end_time()); + static bool first_show=true; + if (first_show) + { + database_timer_callback(this); + first_show = false; + } } -void c_trend_view::on_update_trend_view(int id, int param) +void c_trend_view::update_trend_view() { - //update time bar c_time_bar* p_time_bar = (c_time_bar*)get_wnd_ptr(ID_TREND_SCREEN_TIME_SCALE_BAR_CTRL); p_time_bar->set_time(get_time_in_second()); - on_time_bar_change(0, 0); + refresh_trend_table(p_time_bar->get_start_time(), p_time_bar->get_end_time()); + refresh_trend_graphic(p_time_bar->get_end_time()); } void c_trend_view::refresh_trend_table(long start_time, long end_time) @@ -187,6 +182,30 @@ int c_trend_view::read_trend_data(long start_time, long end_time, int hr[], int } time += detal; } - return read_cnt; } + +typedef int(*SYNC_DATA)(int hr, int spo2, int rr, int nibp_sys, int nibp_dia, int nibp_mean); +extern SYNC_DATA gSyncData; +void c_trend_view::database_timer_callback(void* param) +{ + VALUE_SET data; + memset(&data, 0, sizeof(data)); + c_value_manager* real_data_mgr = c_value_manager::get_instance(); + + data.time = get_time_in_second(); + data.hr = data.pr = real_data_mgr->get_value(VALUE_HR); + data.spo2 = real_data_mgr->get_value(VALUE_SPO2); + data.rr = real_data_mgr->get_value(VALUE_RESP); + data.nibp_sys = real_data_mgr->get_value(VALUE_NIBP_SYS); + data.nibp_dia = real_data_mgr->get_value(VALUE_NIBP_DIA); + data.nibp_mean = real_data_mgr->get_value(VALUE_NIBP_MEAN); + c_database::get_instance()->write(data); + + ((c_trend_view*)param)->update_trend_view(); + + if (gSyncData) + { + gSyncData(data.hr, data.spo2, data.rr, data.nibp_sys, data.nibp_dia, data.nibp_mean); + } +} diff --git a/HostMonitor/UIcode/source/ui_layout/View/trend/trend_view.h b/HostMonitor/UIcode/source/ui_layout/View/trend/trend_view.h index 99c947146fc8341d1ff9816087beee90499b0ec9..02d5bba50705460ab96e9509bb0f10848ddbe424 100644 --- a/HostMonitor/UIcode/source/ui_layout/View/trend/trend_view.h +++ b/HostMonitor/UIcode/source/ui_layout/View/trend/trend_view.h @@ -8,13 +8,11 @@ public: virtual void on_init_children(void); virtual void on_paint(void); private: - void on_time_bar_change(int ctrl_id, int param); - void on_update_trend_view(int id, int param); + void update_trend_view(); virtual void refresh_trend_table(long start_time, long end_time);//time unit: second virtual void refresh_trend_graphic(long time);//time unit: second - int read_trend_data(long start_time, long end_time, int hr[], int spo2[], int rr[], int pr[], - int nibp_sys[], int nibp_dia[], int nibp_mean[], int len);//time unit: second - GL_DECLARE_MESSAGE_MAP() + int read_trend_data(long start_time, long end_time, int hr[], int spo2[], int rr[], int pr[], int nibp_sys[], int nibp_dia[], int nibp_mean[], int len);//time unit: second + static void database_timer_callback(void* param); }; #endif diff --git a/HostMonitor/UIcode/source/ui_layout/slide_config.cpp b/HostMonitor/UIcode/source/ui_layout/slide_config.cpp index b65a07351c0a6fbbb04ec1904f5caa4d697a0b02..90d61403c846227bc46891990cee1f370c66b4bd 100644 --- a/HostMonitor/UIcode/source/ui_layout/slide_config.cpp +++ b/HostMonitor/UIcode/source/ui_layout/slide_config.cpp @@ -8,29 +8,27 @@ #include "Dialog/about/about_dlg_xml.h" class c_config_root : public c_wnd { - void on_clicked(int ctrl_id, int param); - GL_DECLARE_MESSAGE_MAP() -}; - -GL_BEGIN_MESSAGE_MAP(c_config_root) -ON_GL_BN_CLICKED(c_config_root::on_clicked) -GL_END_MESSAGE_MAP() - -void c_config_root::on_clicked(int ctrl_id, int param) -{ - switch(ctrl_id) + virtual void on_init_children() { - case 5: - c_dialog::open_dialog((c_dialog*)get_wnd_ptr(IDD_SETUP_DLG), false); - break; - case 7: - c_dialog::open_dialog((c_dialog*)get_wnd_ptr(IDD_ABOUT_DLG), false); - break; - default: - ASSERT(false); - break; + ((c_button*)get_wnd_ptr(ID_SETUP_BUTTON))->set_on_click((WND_CALLBACK)&c_config_root::on_clicked); + ((c_button*)get_wnd_ptr(ID_ABOUT_BUTTON))->set_on_click((WND_CALLBACK)&c_config_root::on_clicked); } -} + void on_clicked(int ctrl_id, int param) + { + switch (ctrl_id) + { + case ID_SETUP_BUTTON: + c_dialog::open_dialog((c_dialog*)get_wnd_ptr(ID_SETUP_DLG), false); + break; + case ID_ABOUT_BUTTON: + c_dialog::open_dialog((c_dialog*)get_wnd_ptr(IDD_ABOUT_DLG), false); + break; + default: + ASSERT(false); + break; + } + } +}; ////////////////////////////////////////////////////////////////////////// @@ -49,10 +47,10 @@ static c_about_dlg s_about; static WND_TREE s_config_children[]= { - {&s_btn_patient_setup, 5, "Patient Setup", 0, 5, BUTTON_WIDTH, BUTTON_HEIGHT}, - {&s_btn_demo_setup, 7, "About", (BUTTON_WIDTH + 10), 5, BUTTON_WIDTH, BUTTON_HEIGHT}, + {&s_btn_patient_setup, ID_SETUP_BUTTON, "Patient Setup", 0, 5, BUTTON_WIDTH, BUTTON_HEIGHT}, + {&s_btn_demo_setup, ID_ABOUT_BUTTON, "About", (BUTTON_WIDTH + 10), 5, BUTTON_WIDTH, BUTTON_HEIGHT}, - {&s_patient_setup_dlg, IDD_SETUP_DLG, "Patient Setup", 0, DIALOG_Y, PAGE_WIDTH, DIALOG_HEIGHT, g_patient_setup_children}, + {&s_patient_setup_dlg, ID_SETUP_DLG, "Patient Setup", 0, DIALOG_Y, PAGE_WIDTH, DIALOG_HEIGHT, g_patient_setup_children}, {&s_about, IDD_ABOUT_DLG, "About", 0, DIALOG_Y, PAGE_WIDTH, DIALOG_HEIGHT, g_about_children}, {0,0,0,0,0,0,0} }; diff --git a/HostMonitor/UIcode/source/ui_layout/slide_trend.cpp b/HostMonitor/UIcode/source/ui_layout/slide_trend.cpp index 29bb4899e747062271f3c2e812a4d787653d307b..9f70133d8157d9dd46d5191ddd9ffa0cc32e2789 100644 --- a/HostMonitor/UIcode/source/ui_layout/slide_trend.cpp +++ b/HostMonitor/UIcode/source/ui_layout/slide_trend.cpp @@ -38,7 +38,7 @@ WND_TREE g_page_trend_view_children[] = {0,0,0,0,0,0,0,0 } }; -static c_trend_view s_trend_view; +static c_trend_view s_trend_view; static c_wnd s_root; WND_TREE g_trend_page_children[]=