mirror of
https://gitee.com/idea4good/GuiLite.git
synced 2025-06-28 13:34:07 +08:00
refactor wnd.cpp
This commit is contained in:
parent
5b1bd4f387
commit
f7ac16b4db
42
core/wnd.cpp
42
core/wnd.cpp
@ -287,34 +287,6 @@ void c_wnd::wnd2screen(c_rect &rect) const
|
|||||||
rect.SetRect(l, t, r, b);
|
rect.SetRect(l, t, r, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_wnd::screen2wnd(short &x, short &y) const
|
|
||||||
{
|
|
||||||
c_wnd *parent = m_parent;
|
|
||||||
c_rect rect;
|
|
||||||
|
|
||||||
x -= m_wnd_rect.m_left;
|
|
||||||
y -= m_wnd_rect.m_top;
|
|
||||||
|
|
||||||
while ( 0 != parent )
|
|
||||||
{
|
|
||||||
parent->get_wnd_rect(rect);
|
|
||||||
x -= rect.m_left;
|
|
||||||
y -= rect.m_top;
|
|
||||||
parent = parent->m_parent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void c_wnd::screen2wnd(c_rect &rect) const
|
|
||||||
{
|
|
||||||
short l = rect.m_left;
|
|
||||||
short t = rect.m_top;
|
|
||||||
screen2wnd(l, t);
|
|
||||||
|
|
||||||
short r = l + rect.Width() - 1;
|
|
||||||
short b = t + rect.Height() - 1;
|
|
||||||
rect.SetRect(l, t, r, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
c_wnd* c_wnd::set_child_focus(c_wnd * focus_child)
|
c_wnd* c_wnd::set_child_focus(c_wnd * focus_child)
|
||||||
{
|
{
|
||||||
ASSERT(0 != focus_child);
|
ASSERT(0 != focus_child);
|
||||||
@ -509,9 +481,9 @@ bool c_wnd::on_key(KEY_TYPE key)
|
|||||||
{
|
{
|
||||||
old_focus_wnd = m_focus_child->m_focus_child;
|
old_focus_wnd = m_focus_child->m_focus_child;
|
||||||
}
|
}
|
||||||
if (old_focus_wnd && !old_focus_wnd->on_key(key))
|
if (old_focus_wnd && !old_focus_wnd->on_key(key))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default moving focus(Default handle KEY_FOWARD/KEY_BACKWARD)
|
// Default moving focus(Default handle KEY_FOWARD/KEY_BACKWARD)
|
||||||
@ -561,13 +533,13 @@ bool c_wnd::on_key(KEY_TYPE key)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_wnd::notify_parent(unsigned int msg_id, unsigned int ctrl_id, int param)
|
void c_wnd::notify_parent(unsigned int msg_id, int param)
|
||||||
{
|
{
|
||||||
if (!m_parent)
|
if (!m_parent)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const GL_MSG_ENTRY* entry = m_parent->FindMsgEntry(m_parent->GetMSgEntries(), MSG_TYPE_WND, msg_id, ctrl_id);
|
const GL_MSG_ENTRY* entry = m_parent->FindMsgEntry(m_parent->GetMSgEntries(), MSG_TYPE_WND, msg_id, m_resource_id);
|
||||||
if (0 == entry)
|
if (0 == entry)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -585,10 +557,10 @@ void c_wnd::notify_parent(unsigned int msg_id, unsigned int ctrl_id, int param)
|
|||||||
(m_parent->*msg_funcs.func_vvl)(param);
|
(m_parent->*msg_funcs.func_vvl)(param);
|
||||||
break;
|
break;
|
||||||
case MSG_CALLBACK_VWV:
|
case MSG_CALLBACK_VWV:
|
||||||
(m_parent->*msg_funcs.func_vwv)(ctrl_id);
|
(m_parent->*msg_funcs.func_vwv)(m_resource_id);
|
||||||
break;
|
break;
|
||||||
case MSG_CALLBACK_VWL:
|
case MSG_CALLBACK_VWL:
|
||||||
(m_parent->*msg_funcs.func_vwl)(ctrl_id, param);
|
(m_parent->*msg_funcs.func_vwl)(m_resource_id, param);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
|
@ -92,7 +92,7 @@ public:
|
|||||||
c_wnd* get_prev_sibling() const { return m_prev_sibling; }
|
c_wnd* get_prev_sibling() const { return m_prev_sibling; }
|
||||||
c_wnd* get_next_sibling() const { return m_next_sibling; }
|
c_wnd* get_next_sibling() const { return m_next_sibling; }
|
||||||
|
|
||||||
void notify_parent(unsigned int msg_id, unsigned int ctrl_id, int param);
|
void notify_parent(unsigned int msg_id, int param);
|
||||||
|
|
||||||
virtual bool on_touch(int x, int y, TOUCH_ACTION action);// return true: handled; false: not be handled.
|
virtual bool on_touch(int x, int y, TOUCH_ACTION action);// return true: handled; false: not be handled.
|
||||||
virtual bool on_key(KEY_TYPE key);// return false: skip handling by parent;
|
virtual bool on_key(KEY_TYPE key);// return false: skip handling by parent;
|
||||||
@ -105,8 +105,6 @@ protected:
|
|||||||
|
|
||||||
void wnd2screen(int &x, int &y) const;
|
void wnd2screen(int &x, int &y) const;
|
||||||
void wnd2screen(c_rect &rect) const;
|
void wnd2screen(c_rect &rect) const;
|
||||||
void screen2wnd(short &x, short &y) const;
|
|
||||||
void screen2wnd(c_rect &rect) const;
|
|
||||||
|
|
||||||
int load_child_wnd(WND_TREE *p_child_tree);
|
int load_child_wnd(WND_TREE *p_child_tree);
|
||||||
int load_clone_child_wnd(WND_TREE *p_child_tree);
|
int load_clone_child_wnd(WND_TREE *p_child_tree);
|
||||||
|
@ -40,7 +40,7 @@ bool c_button::on_touch(int x, int y, TOUCH_ACTION action)
|
|||||||
{
|
{
|
||||||
m_status = STATUS_FOCUSED;
|
m_status = STATUS_FOCUSED;
|
||||||
on_paint();
|
on_paint();
|
||||||
notify_parent(GL_BN_CLICKED, get_id(), 0);
|
notify_parent(GL_BN_CLICKED, 0);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ bool c_button::on_key(KEY_TYPE key)
|
|||||||
{
|
{
|
||||||
if (key == KEY_ENTER)
|
if (key == KEY_ENTER)
|
||||||
{
|
{
|
||||||
notify_parent(GL_BN_CLICKED, get_id(), 0);
|
notify_parent(GL_BN_CLICKED, 0);
|
||||||
return false;// Do not handle KEY_ENTER by other wnd.
|
return false;// Do not handle KEY_ENTER by other wnd.
|
||||||
}
|
}
|
||||||
return true;// Handle KEY_FOWARD/KEY_BACKWARD by parent wnd.
|
return true;// Handle KEY_FOWARD/KEY_BACKWARD by parent wnd.
|
||||||
|
@ -184,13 +184,13 @@ void c_keyboard::on_caps_clicked(unsigned int ctrl_id)
|
|||||||
void c_keyboard::on_enter_clicked(unsigned int ctrl_id)
|
void c_keyboard::on_enter_clicked(unsigned int ctrl_id)
|
||||||
{
|
{
|
||||||
memset(m_str, 0, sizeof(m_str));
|
memset(m_str, 0, sizeof(m_str));
|
||||||
notify_parent(KEYBORAD_CLICK, get_id(), CLICK_ENTER);
|
notify_parent(KEYBORAD_CLICK, CLICK_ENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_keyboard::on_esc_clicked(unsigned int ctrl_id)
|
void c_keyboard::on_esc_clicked(unsigned int ctrl_id)
|
||||||
{
|
{
|
||||||
memset(m_str, 0, sizeof(m_str));
|
memset(m_str, 0, sizeof(m_str));
|
||||||
notify_parent(KEYBORAD_CLICK, get_id(), CLICK_ESC);
|
notify_parent(KEYBORAD_CLICK, CLICK_ESC);
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_keyboard::on_del_clicked(unsigned int ctrl_id)
|
void c_keyboard::on_del_clicked(unsigned int ctrl_id)
|
||||||
@ -200,7 +200,7 @@ void c_keyboard::on_del_clicked(unsigned int ctrl_id)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_str[--m_str_len] = 0;
|
m_str[--m_str_len] = 0;
|
||||||
notify_parent(KEYBORAD_CLICK, get_id(), CLICK_CHAR);
|
notify_parent(KEYBORAD_CLICK, CLICK_CHAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_keyboard::on_char_clicked(unsigned int ctrl_id)
|
void c_keyboard::on_char_clicked(unsigned int ctrl_id)
|
||||||
@ -225,7 +225,7 @@ void c_keyboard::on_char_clicked(unsigned int ctrl_id)
|
|||||||
ASSERT(false);
|
ASSERT(false);
|
||||||
InputChar:
|
InputChar:
|
||||||
m_str[m_str_len++] = ctrl_id;
|
m_str[m_str_len++] = ctrl_id;
|
||||||
notify_parent(KEYBORAD_CLICK, get_id(), CLICK_CHAR);
|
notify_parent(KEYBORAD_CLICK, CLICK_CHAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_keyboard::on_paint()
|
void c_keyboard::on_paint()
|
||||||
|
@ -109,7 +109,7 @@ void c_list_box::on_touch_down(int x, int y)
|
|||||||
{
|
{
|
||||||
m_status = STATUS_FOCUSED;
|
m_status = STATUS_FOCUSED;
|
||||||
on_paint();
|
on_paint();
|
||||||
notify_parent(GL_LIST_CONFIRM, get_id(), m_selected_item);
|
notify_parent(GL_LIST_CONFIRM, m_selected_item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ void c_list_box::on_touch_up(int x, int y)
|
|||||||
m_status = STATUS_FOCUSED;
|
m_status = STATUS_FOCUSED;
|
||||||
select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT);
|
select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT);
|
||||||
on_paint();
|
on_paint();
|
||||||
notify_parent(GL_LIST_CONFIRM, get_id(), m_selected_item);
|
notify_parent(GL_LIST_CONFIRM, m_selected_item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -79,7 +79,7 @@ void c_spin_box::on_touch_up(int x, int y)
|
|||||||
m_value = m_cur_value;
|
m_value = m_cur_value;
|
||||||
m_status = STATUS_FOCUSED;
|
m_status = STATUS_FOCUSED;
|
||||||
on_paint();
|
on_paint();
|
||||||
notify_parent(GL_SPIN_CONFIRM, get_id(), m_value);
|
notify_parent(GL_SPIN_CONFIRM, m_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ void c_spin_box::on_arrow_up_bt_click(unsigned int ctr_id)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_cur_value += m_step;
|
m_cur_value += m_step;
|
||||||
notify_parent(GL_SPIN_CHANGE, get_id(), m_cur_value);
|
notify_parent(GL_SPIN_CHANGE, m_cur_value);
|
||||||
on_paint();
|
on_paint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,6 +179,6 @@ void c_spin_box::on_arrow_down_bt_click(unsigned int ctr_id)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_cur_value -= m_step;
|
m_cur_value -= m_step;
|
||||||
notify_parent(GL_SPIN_CHANGE, get_id(), m_cur_value);
|
notify_parent(GL_SPIN_CHANGE, m_cur_value);
|
||||||
on_paint();
|
on_paint();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user