diff --git a/GuiLite.cpp b/GuiLite.cpp
index 763c2fd..7ccee4c 100644
--- a/GuiLite.cpp
+++ b/GuiLite.cpp
@@ -960,71 +960,6 @@ int c_wnd::load_child_wnd(WND_TREE *p_child_tree)
}
return sum;
}
-c_wnd* c_wnd::connect_clone(c_wnd *parent, unsigned short resource_id, const char* str,
- short x, short y, short width, short height, WND_TREE* p_child_tree )
-{
- if(0 == resource_id)
- {
- ASSERT(false);
- return 0;
- }
- c_wnd* wnd = clone();
- wnd->m_id = resource_id;
- wnd->set_str(str);
- wnd->m_parent = parent;
- wnd->m_status = STATUS_NORMAL;
- if (parent)
- {
- wnd->m_z_order = parent->m_z_order;
- wnd->m_surface = parent->m_surface;
- }
- else
- {
- wnd->m_surface = m_surface;
- }
- if(0 == wnd->m_surface)
- {
- ASSERT(false);
- return 0;
- }
- /* (cs.x = x * 1024 / 768) for 1027*768=>800*600 quickly*/
- wnd->m_wnd_rect.m_left = x;
- wnd->m_wnd_rect.m_top = y;
- wnd->m_wnd_rect.m_right = (x + width - 1);
- wnd->m_wnd_rect.m_bottom = (y + height - 1);
- c_rect rect;
- wnd->get_screen_rect(rect);
- ASSERT(wnd->m_surface->is_valid(rect));
- wnd->pre_create_wnd();
-
- if ( 0 != parent )
- {
- parent->add_child_2_tail(wnd);
- }
- if (wnd->load_clone_child_wnd(p_child_tree) >= 0)
- {
- wnd->load_cmd_msg();
- wnd->on_init_children();
- }
- return wnd;
-}
-int c_wnd::load_clone_child_wnd(WND_TREE *p_child_tree)
-{
- if (0 == p_child_tree)
- {
- return 0;
- }
- int sum = 0;
- WND_TREE* p_cur = p_child_tree;
- while(p_cur->p_wnd)
- {
- p_cur->p_wnd->connect_clone(this, p_cur->resource_id, p_cur->str,
- p_cur->x, p_cur->y, p_cur->width, p_cur->height,p_cur->p_child_tree);
- p_cur++;
- sum++;
- }
- return sum;
-}
void c_wnd::disconnect()
{
if (0 == m_id)
@@ -1062,33 +997,9 @@ c_wnd* c_wnd::get_wnd_ptr(unsigned short id) const
}
return child;
}
-void c_wnd::set_attr(WND_ATTRIBUTION attr)
-{
- m_attr = attr;
- if ( ATTR_DISABLED == (attr & ATTR_DISABLED) )
- {
- m_status = STATUS_DISABLED;
- }
- else
- {
- if (m_status == STATUS_DISABLED)
- {
- m_status = STATUS_NORMAL;
- }
- }
-}
bool c_wnd::is_focus_wnd() const
{
- if ( (m_attr & ATTR_VISIBLE)
- && !(m_attr & ATTR_DISABLED)
- && (m_attr & ATTR_FOCUS))
- {
- return true;
- }
- else
- {
- return false;
- }
+ return ((m_attr & ATTR_VISIBLE) && (m_attr & ATTR_FOCUS)) ? true : false;
}
void c_wnd::set_wnd_pos(short x, short y, short width, short height)
{
@@ -1143,10 +1054,6 @@ c_wnd* c_wnd::set_child_focus(c_wnd * focus_child)
old_focus_child->on_kill_focus();
}
m_focus_child = focus_child;
- if (m_parent)
- {
- m_parent->set_child_focus(this);
- }
m_focus_child->on_focus();
}
}
@@ -1257,76 +1164,88 @@ void c_wnd::show_window()
}
}
}
-bool c_wnd::on_touch(int x, int y, TOUCH_ACTION action)
+void c_wnd::on_touch(int x, int y, TOUCH_ACTION action)
{
- c_rect rect;
+ c_wnd* model_wnd = 0;
+ c_wnd* tmp_child = m_top_child;
+ while (tmp_child)
+ {
+ if ((tmp_child->m_attr & ATTR_MODAL) && (tmp_child->m_attr & ATTR_VISIBLE))
+ {
+ model_wnd = tmp_child;
+ break;
+ }
+ tmp_child = tmp_child->m_next_sibling;
+ }
+ if (model_wnd)
+ {
+ return model_wnd->on_touch(x, y, action);
+ }
x -= m_wnd_rect.m_left;
y -= m_wnd_rect.m_top;
c_wnd* child = m_top_child;
- c_wnd* target_wnd = 0;
- int target_z_order = Z_ORDER_LEVEL_0;
while (child)
{
- if (ATTR_VISIBLE == (child->m_attr & ATTR_VISIBLE))
+ if (child->is_focus_wnd())
{
+ c_rect rect;
child->get_wnd_rect(rect);
- if (true == rect.PtInRect(x, y) || child->m_attr & ATTR_MODAL)
+ if (true == rect.PtInRect(x, y))
{
- if (true == child->is_focus_wnd())
- {
- if (child->m_z_order >= target_z_order)
- {
- target_wnd = child;
- target_z_order = child->m_z_order;
- }
- }
+ return child->on_touch(x, y, action);
}
}
child = child->m_next_sibling;
}
- if (target_wnd == 0)
- {
- return false;
- }
- return target_wnd->on_touch(x, y, action);
}
-bool c_wnd::on_key(KEY_TYPE key)
+void c_wnd::on_key(KEY_TYPE key)
{
- ASSERT(key == KEY_FORWARD || key == KEY_BACKWARD || key == KEY_ENTER);
- // Find current focus wnd.
+ c_wnd* model_wnd = 0;
+ c_wnd* tmp_child = m_top_child;
+ while (tmp_child)
+ {
+ if ((tmp_child->m_attr & ATTR_MODAL) && (tmp_child->m_attr & ATTR_VISIBLE))
+ {
+ model_wnd = tmp_child;
+ break;
+ }
+ tmp_child = tmp_child->m_next_sibling;
+ }
+ if (model_wnd)
+ {
+ return model_wnd->on_key(key);
+ }
+ if (!is_focus_wnd())
+ {
+ return;
+ }
+ if (key != KEY_BACKWARD && key != KEY_FORWARD)
+ {
+ if (m_focus_child)
+ {
+ m_focus_child->on_key(key);
+ }
+ return;
+ }
+ // Move focus
c_wnd* old_focus_wnd = m_focus_child;
- while (m_focus_child && 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))
- {
- return true;
- }
- // Default moving focus(Default handle KEY_FOWARD/KEY_BACKWARD)
- if (key == KEY_ENTER)
- {
- return true;
- }
+ // No current focus wnd, new one.
if (!old_focus_wnd)
- {// No current focus wnd, new one.
- c_wnd *child = m_top_child;
- c_wnd *new_focus_wnd = 0;
+ {
+ c_wnd* child = m_top_child;
+ c_wnd* new_focus_wnd = 0;
while (child)
{
- if (ATTR_VISIBLE == (child->m_attr & ATTR_VISIBLE))
+ if (child->is_focus_wnd())
{
- if (true == child->is_focus_wnd())
- {
- new_focus_wnd = child;
- new_focus_wnd->m_parent->set_child_focus(new_focus_wnd);
- child = child->m_top_child;
- continue;
- }
+ new_focus_wnd = child;
+ new_focus_wnd->m_parent->set_child_focus(new_focus_wnd);
+ child = child->m_top_child;
+ continue;
}
child = child->m_next_sibling;
}
- return true;
+ return;
}
// Move focus from old wnd to next wnd
c_wnd* next_focus_wnd = (key == KEY_FORWARD) ? old_focus_wnd->m_next_sibling : old_focus_wnd->m_prev_sibling;
@@ -1346,7 +1265,6 @@ bool c_wnd::on_key(KEY_TYPE key)
{
next_focus_wnd->m_parent->set_child_focus(next_focus_wnd);
}
- return true;
}
void c_wnd::notify_parent(int msg_id, int param)
{
@@ -2739,7 +2657,7 @@ void c_button::on_kill_focus()
m_status = STATUS_NORMAL;
on_paint();
}
-bool c_button::on_touch(int x, int y, TOUCH_ACTION action)
+void c_button::on_touch(int x, int y, TOUCH_ACTION action)
{
if (action == TOUCH_DOWN)
{
@@ -2753,16 +2671,20 @@ bool c_button::on_touch(int x, int y, TOUCH_ACTION action)
on_paint();
notify_parent(GL_BN_CLICKED, 0);
}
- return true;
}
-bool c_button::on_key(KEY_TYPE key)
+void c_button::on_key(KEY_TYPE key)
{
- if (key == KEY_ENTER)
+ switch (key)
{
- notify_parent(GL_BN_CLICKED, 0);
- return false;// Do not handle KEY_ENTER by other wnd.
+ case KEY_ENTER:
+ on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_DOWN);
+ on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_UP);
+ break;
+ case KEY_FORWARD:
+ case KEY_BACKWARD:
+ break;
}
- return true;// Handle KEY_FOWARD/KEY_BACKWARD by parent wnd.
+ return c_wnd::on_key(key);
}
void c_button::on_paint()
{
@@ -2918,10 +2840,21 @@ void c_edit::set_text(const char* str)
strcpy(m_str, str);
}
}
-bool c_edit::on_touch(int x, int y, TOUCH_ACTION action)
+void c_edit::on_key(KEY_TYPE key)
+{
+ switch (key)
+ {
+ case KEY_ENTER:
+ (m_status == STATUS_PUSHED) ? s_keyboard.on_key(key) : (on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_DOWN), on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_UP));
+ return;
+ case KEY_BACKWARD:
+ case KEY_FORWARD:
+ return (m_status == STATUS_PUSHED) ? s_keyboard.on_key(key) : c_wnd::on_key(key);
+ }
+}
+void c_edit::on_touch(int x, int y, TOUCH_ACTION action)
{
(action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y);
- return true;
}
void c_edit::on_touch_down(int x, int y)
{
@@ -3585,10 +3518,33 @@ void c_list_box::on_paint()
ASSERT(false);
}
}
-bool c_list_box::on_touch(int x, int y, TOUCH_ACTION action)
+void c_list_box::on_key(KEY_TYPE key)
+{
+ switch (key)
+ {
+ case KEY_ENTER:
+ on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_DOWN);
+ on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_UP);
+ return;
+ case KEY_BACKWARD:
+ if (m_status != STATUS_PUSHED)
+ {
+ return c_wnd::on_key(key);
+ }
+ m_selected_item = (m_selected_item > 0) ? (m_selected_item - 1) : m_selected_item;
+ return show_list();
+ case KEY_FORWARD:
+ if (m_status != STATUS_PUSHED)
+ {
+ return c_wnd::on_key(key);
+ }
+ m_selected_item = (m_selected_item < (m_item_total - 1)) ? (m_selected_item + 1) : m_selected_item;
+ return show_list();
+ }
+}
+void c_list_box::on_touch(int x, int y, TOUCH_ACTION action)
{
(action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y);
- return true;
}
void c_list_box::on_touch_down(int x, int y)
{
@@ -3779,45 +3735,6 @@ int c_slide_group::add_slide(c_wnd* slide, unsigned short resource_id, short x,
ASSERT(false);
return -3;
}
-int c_slide_group::add_clone_silde(c_wnd* slide, unsigned short resource_id, short x, short y,
- short width, short height, WND_TREE* p_child_tree, Z_ORDER_LEVEL max_zorder)
-{
- if(0 == slide)
- {
- return -1;
- }
- c_surface* old_surface = get_surface();
- c_surface* new_surface = old_surface->get_display()->alloc_surface(max_zorder);
- new_surface->set_active(false);
- set_surface(new_surface);
- c_wnd* page_tmp = slide->connect_clone(this,resource_id,0,x,y,width,height,p_child_tree);
- set_surface(old_surface);
- int i = 0;
- while(i < MAX_PAGES)
- {
- if(m_slides[i] == page_tmp)
- {//slide has lived
- ASSERT(false);
- return -2;
- }
- i++;
- }
- //new slide
- i = 0;
- while(i < MAX_PAGES)
- {
- if(m_slides[i] == 0)
- {
- m_slides[i] = page_tmp;
- page_tmp->show_window();
- return 0;
- }
- i++;
- }
- //no more slide can be add
- ASSERT(false);
- return -3;
-}
void c_slide_group::disabel_all_slide()
{
for(int i = 0; i < MAX_PAGES; i++)
@@ -3828,7 +3745,7 @@ void c_slide_group::disabel_all_slide()
}
}
}
-bool c_slide_group::on_touch(int x, int y, TOUCH_ACTION action)
+void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action)
{
x -= m_wnd_rect.m_left;
y -= m_wnd_rect.m_top;
@@ -3839,164 +3756,49 @@ bool c_slide_group::on_touch(int x, int y, TOUCH_ACTION action)
m_slides[m_active_slide_index]->on_touch(x, y, action);
}
}
- return true;
}
-bool c_slide_group::on_key(KEY_TYPE key)
+void c_slide_group::on_key(KEY_TYPE key)
{
if (m_slides[m_active_slide_index])
{
m_slides[m_active_slide_index]->on_key(key);
}
- return true;
}
-#define ARROW_BT_HEIGHT 55
-#define ID_BT_ARROW_UP 1
-#define ID_BT_ARROW_DOWN 2
-GL_BEGIN_MESSAGE_MAP(c_spin_box)
-ON_GL_BN_CLICKED(c_spin_box::on_arrow_bt_click)
-GL_END_MESSAGE_MAP()
+#define ARROW_BT_WIDTH 55
+#define ID_BT_ARROW_UP 0x1111
+#define ID_BT_ARROW_DOWN 0x2222
+void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action)
+{
+ if (action == TOUCH_UP)
+ {
+ (m_id == ID_BT_ARROW_UP) ? m_spin_box->on_arrow_up_bt_click() : m_spin_box->on_arrow_down_bt_click();
+ }
+ c_button::on_touch(x, y, action);
+}
void c_spin_box::pre_create_wnd()
{
- m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS);
+ m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE);
m_font_type = c_theme::get_font(FONT_DEFAULT);
m_font_color = c_theme::get_color(COLOR_WND_FONT);
m_max = 6;
m_min = 1;
m_digit = 0;
m_step = 1;
- //set arrow button position.
+ //link arrow button position.
c_rect rect;
get_screen_rect(rect);
- m_bt_up_rect.m_left = rect.m_left;
- m_bt_up_rect.m_right = rect.m_left + rect.Width() / 2 - 1;
- m_bt_up_rect.m_top = rect.m_bottom + 1;
- m_bt_up_rect.m_bottom = m_bt_up_rect.m_top + ARROW_BT_HEIGHT;
- m_bt_down_rect.m_left = rect.m_left + rect.Width() / 2;
- m_bt_down_rect.m_right = rect.m_right;
- m_bt_down_rect.m_top = rect.m_bottom + 1;
- m_bt_down_rect.m_bottom = m_bt_down_rect.m_top + ARROW_BT_HEIGHT;
-}
-bool c_spin_box::on_touch(int x, int y, TOUCH_ACTION action)
-{
- (action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y);
- return c_wnd::on_touch(x, y, action);
-}
-void c_spin_box::on_touch_down(int x, int y)
-{
- if (false == m_wnd_rect.PtInRect(x, y))
- {//maybe click on up/down arrow button
- return;
- }
- if (STATUS_NORMAL == m_status)
- {
- m_parent->set_child_focus(this);
- }
-}
-void c_spin_box::on_touch_up(int x, int y)
-{
- if (false == m_wnd_rect.PtInRect(x, y))
- {//maybe click on up/down arrow button
- return;
- }
- if (STATUS_FOCUSED == m_status)
- {
- m_status = STATUS_PUSHED;
- on_paint();
- }
- else if (STATUS_PUSHED == m_status)
- {
- m_value = m_cur_value;
- m_status = STATUS_FOCUSED;
- on_paint();
- notify_parent(GL_SPIN_CONFIRM, m_value);
- }
-}
-void c_spin_box::on_focus()
-{
- m_status = STATUS_FOCUSED;
- on_paint();
-}
-void c_spin_box::on_kill_focus()
-{
- m_cur_value = m_value;
- m_status = STATUS_NORMAL;
- on_paint();
-}
-void c_spin_box::show_arrow_button()
-{
- m_bt_up.connect(this, ID_BT_ARROW_UP, "\xe2\x96\xb2"/*unicode of up arrow*/, 0, m_wnd_rect.Height(), m_bt_up_rect.Width(),m_bt_up_rect.Height());
- m_bt_up.show_window();
- m_bt_down.connect(this, ID_BT_ARROW_DOWN, "\xe2\x96\xbc"/*unicode of down arrow*/, m_bt_up_rect.Width(), m_wnd_rect.Height(), m_bt_down_rect.Width(),m_bt_down_rect.Height());
- m_bt_down.show_window();
- m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_MODAL);
-}
-void c_spin_box::hide_arrow_button()
-{
- m_bt_up.disconnect();
- m_bt_down.disconnect();
- m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS);
+ m_bt_down.m_spin_box = m_bt_up.m_spin_box = this;
+ m_bt_down.connect(m_parent, ID_BT_ARROW_DOWN, "-", rect.m_left - ARROW_BT_WIDTH, rect.m_top, ARROW_BT_WIDTH, rect.Height());
+ m_bt_up.connect(m_parent, ID_BT_ARROW_UP, "+", rect.m_right, rect.m_top, ARROW_BT_WIDTH, rect.Height());
}
void c_spin_box::on_paint()
{
- c_rect rect, tmp_rect, empty_rect;
+ c_rect rect;
get_screen_rect(rect);
- tmp_rect.m_left = rect.m_left;
- tmp_rect.m_right = rect.m_right;
- switch(m_status)
- {
- case STATUS_NORMAL:
- if (m_z_order > m_parent->get_z_order())
- {
- hide_arrow_button();
- m_surface->set_frame_layer_visible_rect(empty_rect, m_z_order);
- m_z_order = m_parent->get_z_order();
- }
- m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order);
- c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER);
- break;
- case STATUS_FOCUSED:
- if (m_z_order > m_parent->get_z_order())
- {
- hide_arrow_button();
- m_surface->set_frame_layer_visible_rect(empty_rect, m_z_order);
- m_z_order = m_parent->get_z_order();
- }
- m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order);
- c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER);
- break;
- case STATUS_PUSHED:
- if (m_z_order == m_parent->get_z_order())
- {
- m_z_order++;
- }
- tmp_rect.m_top = m_bt_down_rect.m_top;
- tmp_rect.m_bottom = m_bt_down_rect.m_bottom;
- m_surface->set_frame_layer_visible_rect(tmp_rect, m_z_order);
- show_arrow_button();
- m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order());
- m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2);
- c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER);
- break;
- default:
- ASSERT(false);
- }
+ m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order);
+ c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER);
}
-void c_spin_box::on_arrow_bt_click(int ctr_id, int param)
-{
- switch (ctr_id)
- {
- case ID_BT_ARROW_UP:
- on_arrow_up_bt_click(ctr_id, param);
- break;
- case ID_BT_ARROW_DOWN:
- on_arrow_down_bt_click(ctr_id, param);
- break;
- default:
- ASSERT(false);
- break;
- }
-}
-void c_spin_box::on_arrow_up_bt_click(int ctr_id, int param)
+void c_spin_box::on_arrow_up_bt_click()
{
if (m_cur_value + m_step > m_max)
{
@@ -4006,7 +3808,7 @@ void c_spin_box::on_arrow_up_bt_click(int ctr_id, int param)
notify_parent(GL_SPIN_CHANGE, m_cur_value);
on_paint();
}
-void c_spin_box::on_arrow_down_bt_click(int ctr_id, int param)
+void c_spin_box::on_arrow_down_bt_click()
{
if (m_cur_value - m_step < m_min)
{
@@ -4016,6 +3818,12 @@ void c_spin_box::on_arrow_down_bt_click(int ctr_id, int param)
notify_parent(GL_SPIN_CHANGE, m_cur_value);
on_paint();
}
+void c_table::pre_create_wnd()
+{
+ m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE);
+ m_font_type = c_theme::get_font(FONT_DEFAULT);
+ m_font_color = c_theme::get_color(COLOR_WND_FONT);
+}
void c_table::set_item(int row, int col, char* str, unsigned int color)
{
draw_item( row, col, str, color);
diff --git a/GuiLite.h b/GuiLite.h
index 6d566d5..4f73f42 100644
--- a/GuiLite.h
+++ b/GuiLite.h
@@ -356,8 +356,7 @@ class c_wnd;
class c_surface;
typedef enum
{
- ATTR_VISIBLE = 0x80000000L,
- ATTR_DISABLED = 0x40000000L,
+ ATTR_VISIBLE = 0x40000000L,
ATTR_FOCUS = 0x20000000L,
ATTR_MODAL = 0x10000000L// Handle touch action at high priority
}WND_ATTRIBUTION;
@@ -398,10 +397,7 @@ public:
virtual ~c_wnd() {};
virtual int connect(c_wnd *parent, unsigned short resource_id, const char* str,
short x, short y, short width, short height, WND_TREE* p_child_tree = 0);
- virtual c_wnd* connect_clone(c_wnd *parent, unsigned short resource_id, const char* str,
- short x, short y, short width, short height, WND_TREE* p_child_tree = 0);
void disconnect();
- virtual c_wnd* clone() = 0;
virtual void on_init_children() {}
virtual void on_paint() {}
virtual void show_window();
@@ -409,8 +405,8 @@ public:
int get_z_order() { return m_z_order; }
c_wnd* get_wnd_ptr(unsigned short id) const;
unsigned int get_attr() const { return m_attr; }
- void set_attr(WND_ATTRIBUTION attr);
void set_str(const char* str) { m_str = str; }
+ void set_attr(WND_ATTRIBUTION attr) { m_attr = attr; }
bool is_focus_wnd() const;
void set_font_color(unsigned int color) { m_font_color = color; }
unsigned int get_font_color() { return m_font_color; }
@@ -428,8 +424,8 @@ 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);
- 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 void on_touch(int x, int y, TOUCH_ACTION action);
+ virtual void on_key(KEY_TYPE key);
c_surface* get_surface() { return m_surface; }
void set_surface(c_surface* surface) { m_surface = surface; }
protected:
@@ -438,7 +434,6 @@ protected:
void wnd2screen(int &x, int &y) const;
void wnd2screen(c_rect &rect) const;
int load_child_wnd(WND_TREE *p_child_tree);
- int load_clone_child_wnd(WND_TREE *p_child_tree);
void set_active_child(c_wnd* child) { m_focus_child = child; }
virtual void on_focus() {};
virtual void on_kill_focus() {};
@@ -487,15 +482,13 @@ private:
typedef struct struct_bitmap_info BITMAP_INFO;
class c_button : public c_wnd
{
-public:
- virtual c_wnd* clone(){return new c_button();}
protected:
virtual void on_paint();
virtual void on_focus();
virtual void on_kill_focus();
virtual void pre_create_wnd();
- virtual bool on_touch(int x, int y, TOUCH_ACTION action);
- virtual bool on_key(KEY_TYPE key);
+ virtual void on_touch(int x, int y, TOUCH_ACTION action);
+ virtual void on_key(KEY_TYPE key);
};
#endif
#ifndef GUILITE_WIDGETS_INCLUDE_DIALOG_H
@@ -551,7 +544,6 @@ public:
char* get_str() { return m_str; }
protected:
virtual void pre_create_wnd();
- virtual c_wnd* clone(){return new c_keyboard();}
virtual void on_paint();
void on_key_clicked(int id, int param);
void on_char_clicked(int id, int param);
@@ -568,7 +560,6 @@ private:
class c_keyboard_button : public c_button
{
protected:
- virtual c_wnd* clone(){return new c_keyboard_button();}
virtual void on_paint();
};
#endif /* KEYBOARD_H_ */
@@ -579,7 +570,6 @@ class c_edit : public c_wnd
{
friend class c_keyboard;
public:
- virtual c_wnd* clone(){return new c_edit();}
const char* get_text(){return m_str;}
void set_text(const char* str);
void set_keyboard_style(KEYBOARD_STYLE kb_sytle) { m_kb_style = kb_sytle; }
@@ -589,7 +579,8 @@ protected:
virtual void on_paint();
virtual void on_focus();
virtual void on_kill_focus();
- virtual bool on_touch(int x, int y, TOUCH_ACTION action);
+ virtual void on_key(KEY_TYPE key);
+ virtual void on_touch(int x, int y, TOUCH_ACTION action);
void on_key_board_click(int id, int param);
GL_DECLARE_MESSAGE_MAP()
@@ -633,11 +624,9 @@ private:
class c_label : public c_wnd
{
public:
- virtual c_wnd* clone(){return new c_label();}
virtual void on_paint();
protected:
virtual void pre_create_wnd();
-private:
};
#endif
#ifndef GUILITE_WIDGETS_INCLUDE_LIST_BOX_H
@@ -655,12 +644,12 @@ public:
void select_item(short index);
protected:
- virtual c_wnd* clone(){return new c_list_box();}
virtual void pre_create_wnd();
virtual void on_paint();
virtual void on_focus();
virtual void on_kill_focus();
- virtual bool on_touch(int x, int y, TOUCH_ACTION action);
+ virtual void on_key(KEY_TYPE key);
+ virtual void on_touch(int x, int y, TOUCH_ACTION action);
private:
void update_list_size();
@@ -688,14 +677,10 @@ public:
int add_slide(c_wnd* slide, unsigned short resource_id, short x, short y,
short width, short height, WND_TREE* p_child_tree = 0,
Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0);
- int add_clone_silde(c_wnd* slide, unsigned short resource_id, short x, short y,
- short width, short height, WND_TREE* p_child_tree = 0,
- Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0);
void disabel_all_slide();
- virtual bool on_touch(int x, int y, TOUCH_ACTION action);
- virtual bool on_key(KEY_TYPE key);
+ virtual void on_touch(int x, int y, TOUCH_ACTION action);
+ virtual void on_key(KEY_TYPE key);
protected:
- virtual c_wnd* clone(){return new c_slide_group();}
c_wnd* m_slides[MAX_PAGES];
int m_active_slide_index;
c_gesture* m_gesture;
@@ -703,52 +688,42 @@ protected:
#endif
#ifndef GUILITE_WIDGETS_INCLUDE_SPINBOX_H
#define GUILITE_WIDGETS_INCLUDE_SPINBOX_H
-#define GL_SPIN_CONFIRM 0x2222
#define GL_SPIN_CHANGE 0x3333
-#define ON_SPIN_CONFIRM(func) \
-{MSG_TYPE_WND, GL_SPIN_CONFIRM, 0, msgCallback(&func)},
#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
+{
+ friend class c_spin_box;
+ virtual void on_touch(int x, int y, TOUCH_ACTION action);
+ c_spin_box* m_spin_box;
+};
class c_spin_box : public c_wnd
{
+ friend class c_spin_button;
public:
- short get_value(){return m_value;}
- void set_value(unsigned short value){m_value = m_cur_value = value;}
- void set_max_min(short max, short min){m_max = max; m_min = min;}
- void set_step(short step){m_step = step;}
- short get_min(){return m_min;}
- short get_max(){return m_max;}
- short get_step(){return m_step;}
- void set_value_digit(short digit){m_digit = digit;}
- short get_value_digit(){return m_digit;}
-
+ short get_value() { return m_value; }
+ void set_value(unsigned short value) { m_value = m_cur_value = value; }
+ void set_max_min(short max, short min) { m_max = max; m_min = min; }
+ void set_step(short step) { m_step = step; }
+ short get_min() { return m_min; }
+ short get_max() { return m_max; }
+ short get_step() { return m_step; }
+ void set_value_digit(short digit) { m_digit = digit; }
+ short get_value_digit() { return m_digit; }
protected:
- virtual c_wnd* clone(){return new c_spin_box();}
virtual void on_paint();
- virtual void on_focus();
- virtual void on_kill_focus();
virtual void pre_create_wnd();
- virtual bool on_touch(int x, int y, TOUCH_ACTION action);
- void on_arrow_bt_click(int ctr_id, int param);
- void on_arrow_up_bt_click(int ctr_id, int param);
- void on_arrow_down_bt_click(int ctr_id, int param);
- GL_DECLARE_MESSAGE_MAP()
-private:
- void show_arrow_button();
- void hide_arrow_button();
- void on_touch_down(int x, int y);
- void on_touch_up(int x, int y);
-protected:
+ void on_arrow_up_bt_click();
+ void on_arrow_down_bt_click();
short m_cur_value;
short m_value;
short m_step;
short m_max;
short m_min;
short m_digit;
- c_button m_bt_up;
- c_button m_bt_down;
- c_rect m_bt_up_rect;
- c_rect m_bt_down_rect;
+ c_spin_button m_bt_up;
+ c_spin_button m_bt_down;
};
#endif
#ifndef GUILITE_WIDGETS_INCLUDE_TABLE_H
@@ -758,7 +733,6 @@ protected:
class c_table: public c_wnd
{
public:
- virtual c_wnd* clone(){return new c_table();}
void set_sheet_align(unsigned int align_type){ m_align_type = align_type;}
void set_row_num(unsigned int row_num){ m_row_num = row_num;}
void set_col_num(unsigned int col_num){ m_col_num = col_num;}
@@ -771,6 +745,7 @@ public:
unsigned int get_col_num(){ return m_col_num;}
c_rect get_item_rect(int row, int col);
protected:
+ virtual void pre_create_wnd();
void draw_item(int row, int col, const char* str, unsigned int color);
unsigned int m_align_type;
unsigned int m_row_num;
@@ -823,7 +798,6 @@ class c_wave_ctrl : public c_wnd
{
public:
c_wave_ctrl();
- virtual c_wnd* clone(){return new c_wave_ctrl();}
virtual void on_init_children();
virtual void on_paint();
void set_wave_name(char* wave_name){ m_wave_name = wave_name;}
diff --git a/workspace/1h-1cpp.sh b/workspace/1h-1cpp.sh
index 6e5a29f..bc48e23 100644
--- a/workspace/1h-1cpp.sh
+++ b/workspace/1h-1cpp.sh
@@ -1,6 +1,6 @@
./.sync.sh 1h1cpp
-echo "Flatten source code into: GuiLite.h/GuiLite.cpp"
+echo "Merging all source code into: GuiLite.h/GuiLite.cpp"
# build GuiLiteRaw.h
cd core_include
@@ -47,6 +47,7 @@ gcc -c GuiLite.cpp
# clean
rm GuiLiteRaw.h GuiLiteRaw.cpp GuiLiteNoInclude.cpp
+mv GuiLite.h GuiLite.cpp ../
echo "Done!"
-echo "You could find GuiLite.h/GuiLite.cpp in this folder"
+echo "You could find GuiLite.h/GuiLite.cpp in root folder"
diff --git a/workspace/GuiLite.vcxproj b/workspace/GuiLite.vcxproj
index 0968458..990893e 100644
--- a/workspace/GuiLite.vcxproj
+++ b/workspace/GuiLite.vcxproj
@@ -182,7 +182,8 @@
%(AdditionalOptions) /machine:X64
- call "$(SolutionDir)sync_build.bat" "GuiLite"
+
+
diff --git a/workspace/core/wnd.cpp b/workspace/core/wnd.cpp
index 3c386c1..6dc7f60 100644
--- a/workspace/core/wnd.cpp
+++ b/workspace/core/wnd.cpp
@@ -89,80 +89,6 @@ int c_wnd::load_child_wnd(WND_TREE *p_child_tree)
return sum;
}
-c_wnd* c_wnd::connect_clone(c_wnd *parent, unsigned short resource_id, const char* str,
- short x, short y, short width, short height, WND_TREE* p_child_tree )
-{
- if(0 == resource_id)
- {
- ASSERT(false);
- return 0;
- }
-
- c_wnd* wnd = clone();
- wnd->m_id = resource_id;
- wnd->set_str(str);
- wnd->m_parent = parent;
- wnd->m_status = STATUS_NORMAL;
-
- if (parent)
- {
- wnd->m_z_order = parent->m_z_order;
- wnd->m_surface = parent->m_surface;
- }
- else
- {
- wnd->m_surface = m_surface;
- }
- if(0 == wnd->m_surface)
- {
- ASSERT(false);
- return 0;
- }
-
- /* (cs.x = x * 1024 / 768) for 1027*768=>800*600 quickly*/
- wnd->m_wnd_rect.m_left = x;
- wnd->m_wnd_rect.m_top = y;
- wnd->m_wnd_rect.m_right = (x + width - 1);
- wnd->m_wnd_rect.m_bottom = (y + height - 1);
-
- c_rect rect;
- wnd->get_screen_rect(rect);
- ASSERT(wnd->m_surface->is_valid(rect));
-
- wnd->pre_create_wnd();
-
- if ( 0 != parent )
- {
- parent->add_child_2_tail(wnd);
- }
-
- if (wnd->load_clone_child_wnd(p_child_tree) >= 0)
- {
- wnd->load_cmd_msg();
- wnd->on_init_children();
- }
- return wnd;
-}
-
-int c_wnd::load_clone_child_wnd(WND_TREE *p_child_tree)
-{
- if (0 == p_child_tree)
- {
- return 0;
- }
- int sum = 0;
-
- WND_TREE* p_cur = p_child_tree;
- while(p_cur->p_wnd)
- {
- p_cur->p_wnd->connect_clone(this, p_cur->resource_id, p_cur->str,
- p_cur->x, p_cur->y, p_cur->width, p_cur->height,p_cur->p_child_tree);
- p_cur++;
- sum++;
- }
- return sum;
-}
-
void c_wnd::disconnect()
{
if (0 == m_id)
@@ -208,35 +134,9 @@ c_wnd* c_wnd::get_wnd_ptr(unsigned short id) const
return child;
}
-void c_wnd::set_attr(WND_ATTRIBUTION attr)
-{
- m_attr = attr;
-
- if ( ATTR_DISABLED == (attr & ATTR_DISABLED) )
- {
- m_status = STATUS_DISABLED;
- }
- else
- {
- if (m_status == STATUS_DISABLED)
- {
- m_status = STATUS_NORMAL;
- }
- }
-}
-
bool c_wnd::is_focus_wnd() const
{
- if ( (m_attr & ATTR_VISIBLE)
- && !(m_attr & ATTR_DISABLED)
- && (m_attr & ATTR_FOCUS))
- {
- return true;
- }
- else
- {
- return false;
- }
+ return ((m_attr & ATTR_VISIBLE) && (m_attr & ATTR_FOCUS)) ? true : false;
}
void c_wnd::set_wnd_pos(short x, short y, short width, short height)
@@ -302,11 +202,6 @@ c_wnd* c_wnd::set_child_focus(c_wnd * focus_child)
old_focus_child->on_kill_focus();
}
m_focus_child = focus_child;
-
- if (m_parent)
- {
- m_parent->set_child_focus(this);
- }
m_focus_child->on_focus();
}
}
@@ -434,84 +329,93 @@ void c_wnd::show_window()
}
}
-bool c_wnd::on_touch(int x, int y, TOUCH_ACTION action)
+void c_wnd::on_touch(int x, int y, TOUCH_ACTION action)
{
- c_rect rect;
+ c_wnd* model_wnd = 0;
+ c_wnd* tmp_child = m_top_child;
+ while (tmp_child)
+ {
+ if ((tmp_child->m_attr & ATTR_MODAL) && (tmp_child->m_attr & ATTR_VISIBLE))
+ {
+ model_wnd = tmp_child;
+ break;
+ }
+ tmp_child = tmp_child->m_next_sibling;
+ }
+ if (model_wnd)
+ {
+ return model_wnd->on_touch(x, y, action);
+ }
+
x -= m_wnd_rect.m_left;
y -= m_wnd_rect.m_top;
c_wnd* child = m_top_child;
-
- c_wnd* target_wnd = 0;
- int target_z_order = Z_ORDER_LEVEL_0;
-
while (child)
{
- if (ATTR_VISIBLE == (child->m_attr & ATTR_VISIBLE))
+ if (child->is_focus_wnd())
{
+ c_rect rect;
child->get_wnd_rect(rect);
- if (true == rect.PtInRect(x, y) || child->m_attr & ATTR_MODAL)
+ if (true == rect.PtInRect(x, y))
{
- if (true == child->is_focus_wnd())
- {
- if (child->m_z_order >= target_z_order)
- {
- target_wnd = child;
- target_z_order = child->m_z_order;
- }
- }
+ return child->on_touch(x, y, action);
}
}
child = child->m_next_sibling;
}
-
- if (target_wnd == 0)
- {
- return false;
- }
- return target_wnd->on_touch(x, y, action);
}
-bool c_wnd::on_key(KEY_TYPE key)
+void c_wnd::on_key(KEY_TYPE key)
{
- ASSERT(key == KEY_FORWARD || key == KEY_BACKWARD || key == KEY_ENTER);
+ c_wnd* model_wnd = 0;
+ c_wnd* tmp_child = m_top_child;
+ while (tmp_child)
+ {
+ if ((tmp_child->m_attr & ATTR_MODAL) && (tmp_child->m_attr & ATTR_VISIBLE))
+ {
+ model_wnd = tmp_child;
+ break;
+ }
+ tmp_child = tmp_child->m_next_sibling;
+ }
+ if (model_wnd)
+ {
+ return model_wnd->on_key(key);
+ }
- // Find current focus wnd.
+ if (!is_focus_wnd())
+ {
+ return;
+ }
+ if (key != KEY_BACKWARD && key != KEY_FORWARD)
+ {
+ if (m_focus_child)
+ {
+ m_focus_child->on_key(key);
+ }
+ return;
+ }
+
+ // Move focus
c_wnd* old_focus_wnd = m_focus_child;
- while (m_focus_child && 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))
- {
- return true;
- }
-
- // Default moving focus(Default handle KEY_FOWARD/KEY_BACKWARD)
- if (key == KEY_ENTER)
- {
- return true;
- }
+ // No current focus wnd, new one.
if (!old_focus_wnd)
- {// No current focus wnd, new one.
- c_wnd *child = m_top_child;
- c_wnd *new_focus_wnd = 0;
+ {
+ c_wnd* child = m_top_child;
+ c_wnd* new_focus_wnd = 0;
while (child)
{
- if (ATTR_VISIBLE == (child->m_attr & ATTR_VISIBLE))
+ if (child->is_focus_wnd())
{
- if (true == child->is_focus_wnd())
- {
- new_focus_wnd = child;
- new_focus_wnd->m_parent->set_child_focus(new_focus_wnd);
- child = child->m_top_child;
- continue;
- }
+ new_focus_wnd = child;
+ new_focus_wnd->m_parent->set_child_focus(new_focus_wnd);
+ child = child->m_top_child;
+ continue;
}
child = child->m_next_sibling;
}
- return true;
+ return;
}
-
// Move focus from old wnd to next wnd
c_wnd* next_focus_wnd = (key == KEY_FORWARD) ? old_focus_wnd->m_next_sibling : old_focus_wnd->m_prev_sibling;
while (next_focus_wnd && (!next_focus_wnd->is_focus_wnd()))
@@ -530,7 +434,6 @@ bool c_wnd::on_key(KEY_TYPE key)
{
next_focus_wnd->m_parent->set_child_focus(next_focus_wnd);
}
- return true;
}
void c_wnd::notify_parent(int msg_id, int param)
diff --git a/workspace/core_include/wnd.h b/workspace/core_include/wnd.h
index 171e9bc..ecdd962 100644
--- a/workspace/core_include/wnd.h
+++ b/workspace/core_include/wnd.h
@@ -9,8 +9,7 @@ class c_surface;
typedef enum
{
- ATTR_VISIBLE = 0x80000000L,
- ATTR_DISABLED = 0x40000000L,
+ ATTR_VISIBLE = 0x40000000L,
ATTR_FOCUS = 0x20000000L,
ATTR_MODAL = 0x10000000L// Handle touch action at high priority
}WND_ATTRIBUTION;
@@ -56,10 +55,7 @@ public:
virtual ~c_wnd() {};
virtual int connect(c_wnd *parent, unsigned short resource_id, const char* str,
short x, short y, short width, short height, WND_TREE* p_child_tree = 0);
- virtual c_wnd* connect_clone(c_wnd *parent, unsigned short resource_id, const char* str,
- short x, short y, short width, short height, WND_TREE* p_child_tree = 0);
void disconnect();
- virtual c_wnd* clone() = 0;
virtual void on_init_children() {}
virtual void on_paint() {}
virtual void show_window();
@@ -68,9 +64,9 @@ public:
int get_z_order() { return m_z_order; }
c_wnd* get_wnd_ptr(unsigned short id) const;
unsigned int get_attr() const { return m_attr; }
- void set_attr(WND_ATTRIBUTION attr);
void set_str(const char* str) { m_str = str; }
+ void set_attr(WND_ATTRIBUTION attr) { m_attr = attr; }
bool is_focus_wnd() const;
void set_font_color(unsigned int color) { m_font_color = color; }
@@ -94,8 +90,8 @@ public:
void notify_parent(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_key(KEY_TYPE key);// return false: skip handling by parent;
+ virtual void on_touch(int x, int y, TOUCH_ACTION action);
+ virtual void on_key(KEY_TYPE key);
c_surface* get_surface() { return m_surface; }
void set_surface(c_surface* surface) { m_surface = surface; }
@@ -107,7 +103,6 @@ protected:
void wnd2screen(c_rect &rect) const;
int load_child_wnd(WND_TREE *p_child_tree);
- int load_clone_child_wnd(WND_TREE *p_child_tree);
void set_active_child(c_wnd* child) { m_focus_child = child; }
virtual void on_focus() {};
diff --git a/workspace/widgets/button.cpp b/workspace/widgets/button.cpp
index 688d845..5cda563 100644
--- a/workspace/widgets/button.cpp
+++ b/workspace/widgets/button.cpp
@@ -28,7 +28,7 @@ void c_button::on_kill_focus()
on_paint();
}
-bool c_button::on_touch(int x, int y, TOUCH_ACTION action)
+void c_button::on_touch(int x, int y, TOUCH_ACTION action)
{
if (action == TOUCH_DOWN)
{
@@ -42,17 +42,21 @@ bool c_button::on_touch(int x, int y, TOUCH_ACTION action)
on_paint();
notify_parent(GL_BN_CLICKED, 0);
}
- return true;
}
-bool c_button::on_key(KEY_TYPE key)
+void c_button::on_key(KEY_TYPE key)
{
- if (key == KEY_ENTER)
+ switch (key)
{
- notify_parent(GL_BN_CLICKED, 0);
- return false;// Do not handle KEY_ENTER by other wnd.
+ case KEY_ENTER:
+ on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_DOWN);
+ on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_UP);
+ break;
+ case KEY_FORWARD:
+ case KEY_BACKWARD:
+ break;
}
- return true;// Handle KEY_FOWARD/KEY_BACKWARD by parent wnd.
+ return c_wnd::on_key(key);
}
void c_button::on_paint()
diff --git a/workspace/widgets/edit.cpp b/workspace/widgets/edit.cpp
index 3f55c95..eb193d6 100644
--- a/workspace/widgets/edit.cpp
+++ b/workspace/widgets/edit.cpp
@@ -41,10 +41,22 @@ void c_edit::set_text(const char* str)
}
}
-bool c_edit::on_touch(int x, int y, TOUCH_ACTION action)
+void c_edit::on_key(KEY_TYPE key)
+{
+ switch (key)
+ {
+ case KEY_ENTER:
+ (m_status == STATUS_PUSHED) ? s_keyboard.on_key(key) : (on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_DOWN), on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_UP));
+ return;
+ case KEY_BACKWARD:
+ case KEY_FORWARD:
+ return (m_status == STATUS_PUSHED) ? s_keyboard.on_key(key) : c_wnd::on_key(key);
+ }
+}
+
+void c_edit::on_touch(int x, int y, TOUCH_ACTION action)
{
(action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y);
- return true;
}
void c_edit::on_touch_down(int x, int y)
diff --git a/workspace/widgets/list_box.cpp b/workspace/widgets/list_box.cpp
index 38933c4..e696042 100644
--- a/workspace/widgets/list_box.cpp
+++ b/workspace/widgets/list_box.cpp
@@ -84,10 +84,34 @@ void c_list_box::on_paint()
}
}
-bool c_list_box::on_touch(int x, int y, TOUCH_ACTION action)
+void c_list_box::on_key(KEY_TYPE key)
+{
+ switch (key)
+ {
+ case KEY_ENTER:
+ on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_DOWN);
+ on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_UP);
+ return;
+ case KEY_BACKWARD:
+ if (m_status != STATUS_PUSHED)
+ {
+ return c_wnd::on_key(key);
+ }
+ m_selected_item = (m_selected_item > 0) ? (m_selected_item - 1) : m_selected_item;
+ return show_list();
+ case KEY_FORWARD:
+ if (m_status != STATUS_PUSHED)
+ {
+ return c_wnd::on_key(key);
+ }
+ m_selected_item = (m_selected_item < (m_item_total - 1)) ? (m_selected_item + 1) : m_selected_item;
+ return show_list();
+ }
+}
+
+void c_list_box::on_touch(int x, int y, TOUCH_ACTION action)
{
(action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y);
- return true;
}
void c_list_box::on_touch_down(int x, int y)
diff --git a/workspace/widgets/slide_group.cpp b/workspace/widgets/slide_group.cpp
index d18e060..eb7f428 100644
--- a/workspace/widgets/slide_group.cpp
+++ b/workspace/widgets/slide_group.cpp
@@ -100,50 +100,6 @@ int c_slide_group::add_slide(c_wnd* slide, unsigned short resource_id, short x,
return -3;
}
-int c_slide_group::add_clone_silde(c_wnd* slide, unsigned short resource_id, short x, short y,
- short width, short height, WND_TREE* p_child_tree, Z_ORDER_LEVEL max_zorder)
-{
- if(0 == slide)
- {
- return -1;
- }
-
- c_surface* old_surface = get_surface();
- c_surface* new_surface = old_surface->get_display()->alloc_surface(max_zorder);
- new_surface->set_active(false);
- set_surface(new_surface);
- c_wnd* page_tmp = slide->connect_clone(this,resource_id,0,x,y,width,height,p_child_tree);
- set_surface(old_surface);
-
- int i = 0;
- while(i < MAX_PAGES)
- {
- if(m_slides[i] == page_tmp)
- {//slide has lived
- ASSERT(false);
- return -2;
- }
- i++;
- }
-
- //new slide
- i = 0;
- while(i < MAX_PAGES)
- {
- if(m_slides[i] == 0)
- {
- m_slides[i] = page_tmp;
- page_tmp->show_window();
- return 0;
- }
- i++;
- }
-
- //no more slide can be add
- ASSERT(false);
- return -3;
-}
-
void c_slide_group::disabel_all_slide()
{
for(int i = 0; i < MAX_PAGES; i++)
@@ -155,7 +111,7 @@ void c_slide_group::disabel_all_slide()
}
}
-bool c_slide_group::on_touch(int x, int y, TOUCH_ACTION action)
+void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action)
{
x -= m_wnd_rect.m_left;
y -= m_wnd_rect.m_top;
@@ -167,14 +123,12 @@ bool c_slide_group::on_touch(int x, int y, TOUCH_ACTION action)
m_slides[m_active_slide_index]->on_touch(x, y, action);
}
}
- return true;
}
-bool c_slide_group::on_key(KEY_TYPE key)
+void c_slide_group::on_key(KEY_TYPE key)
{
if (m_slides[m_active_slide_index])
{
m_slides[m_active_slide_index]->on_key(key);
}
- return true;
}
diff --git a/workspace/widgets/spinbox.cpp b/workspace/widgets/spinbox.cpp
index 172863a..754aea6 100644
--- a/workspace/widgets/spinbox.cpp
+++ b/workspace/widgets/spinbox.cpp
@@ -9,174 +9,47 @@
#include "../widgets_include/button.h"
#include "../widgets_include/spinbox.h"
-#define ARROW_BT_HEIGHT 55
-#define ID_BT_ARROW_UP 1
-#define ID_BT_ARROW_DOWN 2
+#define ARROW_BT_WIDTH 55
+#define ID_BT_ARROW_UP 0x1111
+#define ID_BT_ARROW_DOWN 0x2222
-GL_BEGIN_MESSAGE_MAP(c_spin_box)
-ON_GL_BN_CLICKED(c_spin_box::on_arrow_bt_click)
-GL_END_MESSAGE_MAP()
+void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action)
+{
+ if (action == TOUCH_UP)
+ {
+ (m_id == ID_BT_ARROW_UP) ? m_spin_box->on_arrow_up_bt_click() : m_spin_box->on_arrow_down_bt_click();
+ }
+ c_button::on_touch(x, y, action);
+}
void c_spin_box::pre_create_wnd()
{
- m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS);
+ m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE);
m_font_type = c_theme::get_font(FONT_DEFAULT);
m_font_color = c_theme::get_color(COLOR_WND_FONT);
-
m_max = 6;
m_min = 1;
m_digit = 0;
m_step = 1;
- //set arrow button position.
+ //link arrow button position.
c_rect rect;
get_screen_rect(rect);
-
- m_bt_up_rect.m_left = rect.m_left;
- m_bt_up_rect.m_right = rect.m_left + rect.Width() / 2 - 1;
- m_bt_up_rect.m_top = rect.m_bottom + 1;
- m_bt_up_rect.m_bottom = m_bt_up_rect.m_top + ARROW_BT_HEIGHT;
-
- m_bt_down_rect.m_left = rect.m_left + rect.Width() / 2;
- m_bt_down_rect.m_right = rect.m_right;
- m_bt_down_rect.m_top = rect.m_bottom + 1;
- m_bt_down_rect.m_bottom = m_bt_down_rect.m_top + ARROW_BT_HEIGHT;
-}
-
-bool c_spin_box::on_touch(int x, int y, TOUCH_ACTION action)
-{
- (action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y);
- return c_wnd::on_touch(x, y, action);
-}
-
-void c_spin_box::on_touch_down(int x, int y)
-{
- if (false == m_wnd_rect.PtInRect(x, y))
- {//maybe click on up/down arrow button
- return;
- }
- if (STATUS_NORMAL == m_status)
- {
- m_parent->set_child_focus(this);
- }
-}
-
-void c_spin_box::on_touch_up(int x, int y)
-{
- if (false == m_wnd_rect.PtInRect(x, y))
- {//maybe click on up/down arrow button
- return;
- }
-
- if (STATUS_FOCUSED == m_status)
- {
- m_status = STATUS_PUSHED;
- on_paint();
- }
- else if (STATUS_PUSHED == m_status)
- {
- m_value = m_cur_value;
- m_status = STATUS_FOCUSED;
- on_paint();
- notify_parent(GL_SPIN_CONFIRM, m_value);
- }
-}
-
-void c_spin_box::on_focus()
-{
- m_status = STATUS_FOCUSED;
- on_paint();
-}
-
-void c_spin_box::on_kill_focus()
-{
- m_cur_value = m_value;
- m_status = STATUS_NORMAL;
- on_paint();
-}
-
-void c_spin_box::show_arrow_button()
-{
- m_bt_up.connect(this, ID_BT_ARROW_UP, "\xe2\x96\xb2"/*unicode of up arrow*/, 0, m_wnd_rect.Height(), m_bt_up_rect.Width(),m_bt_up_rect.Height());
- m_bt_up.show_window();
- m_bt_down.connect(this, ID_BT_ARROW_DOWN, "\xe2\x96\xbc"/*unicode of down arrow*/, m_bt_up_rect.Width(), m_wnd_rect.Height(), m_bt_down_rect.Width(),m_bt_down_rect.Height());
- m_bt_down.show_window();
-
- m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_MODAL);
-}
-
-void c_spin_box::hide_arrow_button()
-{
- m_bt_up.disconnect();
- m_bt_down.disconnect();
- m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS);
+ m_bt_down.m_spin_box = m_bt_up.m_spin_box = this;
+ m_bt_down.connect(m_parent, ID_BT_ARROW_DOWN, "-", rect.m_left - ARROW_BT_WIDTH, rect.m_top, ARROW_BT_WIDTH, rect.Height());
+ m_bt_up.connect(m_parent, ID_BT_ARROW_UP, "+", rect.m_right, rect.m_top, ARROW_BT_WIDTH, rect.Height());
}
void c_spin_box::on_paint()
{
- c_rect rect, tmp_rect, empty_rect;
+ c_rect rect;
get_screen_rect(rect);
- tmp_rect.m_left = rect.m_left;
- tmp_rect.m_right = rect.m_right;
- switch(m_status)
- {
- case STATUS_NORMAL:
- if (m_z_order > m_parent->get_z_order())
- {
- hide_arrow_button();
- m_surface->set_frame_layer_visible_rect(empty_rect, m_z_order);
- m_z_order = m_parent->get_z_order();
- }
- m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order);
- c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER);
- break;
- case STATUS_FOCUSED:
- if (m_z_order > m_parent->get_z_order())
- {
- hide_arrow_button();
- m_surface->set_frame_layer_visible_rect(empty_rect, m_z_order);
- m_z_order = m_parent->get_z_order();
- }
- m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order);
- c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER);
- break;
- case STATUS_PUSHED:
- if (m_z_order == m_parent->get_z_order())
- {
- m_z_order++;
- }
- tmp_rect.m_top = m_bt_down_rect.m_top;
- tmp_rect.m_bottom = m_bt_down_rect.m_bottom;
- m_surface->set_frame_layer_visible_rect(tmp_rect, m_z_order);
- show_arrow_button();
-
- m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order());
- m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2);
- c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER);
- break;
- default:
- ASSERT(false);
- }
+ m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order);
+ c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER);
}
-void c_spin_box::on_arrow_bt_click(int ctr_id, int param)
-{
- switch (ctr_id)
- {
- case ID_BT_ARROW_UP:
- on_arrow_up_bt_click(ctr_id, param);
- break;
- case ID_BT_ARROW_DOWN:
- on_arrow_down_bt_click(ctr_id, param);
- break;
- default:
- ASSERT(false);
- break;
- }
-}
-
-void c_spin_box::on_arrow_up_bt_click(int ctr_id, int param)
+void c_spin_box::on_arrow_up_bt_click()
{
if (m_cur_value + m_step > m_max)
{
@@ -187,7 +60,7 @@ void c_spin_box::on_arrow_up_bt_click(int ctr_id, int param)
on_paint();
}
-void c_spin_box::on_arrow_down_bt_click(int ctr_id, int param)
+void c_spin_box::on_arrow_down_bt_click()
{
if (m_cur_value - m_step < m_min)
{
diff --git a/workspace/widgets/table.cpp b/workspace/widgets/table.cpp
index 006b983..ec12944 100644
--- a/workspace/widgets/table.cpp
+++ b/workspace/widgets/table.cpp
@@ -3,10 +3,18 @@
#include "../core_include/rect.h"
#include "../core_include/word.h"
#include "../core_include/surface.h"
+#include "../core_include/theme.h"
#include "../core_include/cmd_target.h"
#include "../core_include/wnd.h"
#include "../widgets_include/table.h"
+void c_table::pre_create_wnd()
+{
+ m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE);
+ m_font_type = c_theme::get_font(FONT_DEFAULT);
+ m_font_color = c_theme::get_color(COLOR_WND_FONT);
+}
+
void c_table::set_item(int row, int col, char* str, unsigned int color)
{
draw_item( row, col, str, color);
diff --git a/workspace/widgets_include/button.h b/workspace/widgets_include/button.h
index 27ae4ca..ee3cf41 100644
--- a/workspace/widgets_include/button.h
+++ b/workspace/widgets_include/button.h
@@ -8,16 +8,14 @@
typedef struct struct_bitmap_info BITMAP_INFO;
class c_button : public c_wnd
{
-public:
- virtual c_wnd* clone(){return new c_button();}
protected:
virtual void on_paint();
virtual void on_focus();
virtual void on_kill_focus();
virtual void pre_create_wnd();
- virtual bool on_touch(int x, int y, TOUCH_ACTION action);
- virtual bool on_key(KEY_TYPE key);
+ virtual void on_touch(int x, int y, TOUCH_ACTION action);
+ virtual void on_key(KEY_TYPE key);
};
#endif
diff --git a/workspace/widgets_include/edit.h b/workspace/widgets_include/edit.h
index b70a44b..8e26d76 100644
--- a/workspace/widgets_include/edit.h
+++ b/workspace/widgets_include/edit.h
@@ -7,7 +7,6 @@ class c_edit : public c_wnd
{
friend class c_keyboard;
public:
- virtual c_wnd* clone(){return new c_edit();}
const char* get_text(){return m_str;}
void set_text(const char* str);
void set_keyboard_style(KEYBOARD_STYLE kb_sytle) { m_kb_style = kb_sytle; }
@@ -17,7 +16,8 @@ protected:
virtual void on_paint();
virtual void on_focus();
virtual void on_kill_focus();
- virtual bool on_touch(int x, int y, TOUCH_ACTION action);
+ virtual void on_key(KEY_TYPE key);
+ virtual void on_touch(int x, int y, TOUCH_ACTION action);
void on_key_board_click(int id, int param);
GL_DECLARE_MESSAGE_MAP()
diff --git a/workspace/widgets_include/keyboard.h b/workspace/widgets_include/keyboard.h
index 69e5680..04800b8 100644
--- a/workspace/widgets_include/keyboard.h
+++ b/workspace/widgets_include/keyboard.h
@@ -32,7 +32,6 @@ public:
char* get_str() { return m_str; }
protected:
virtual void pre_create_wnd();
- virtual c_wnd* clone(){return new c_keyboard();}
virtual void on_paint();
void on_key_clicked(int id, int param);
@@ -52,7 +51,6 @@ private:
class c_keyboard_button : public c_button
{
protected:
- virtual c_wnd* clone(){return new c_keyboard_button();}
virtual void on_paint();
};
diff --git a/workspace/widgets_include/label.h b/workspace/widgets_include/label.h
index 71c48c1..e900117 100644
--- a/workspace/widgets_include/label.h
+++ b/workspace/widgets_include/label.h
@@ -4,11 +4,9 @@
class c_label : public c_wnd
{
public:
- virtual c_wnd* clone(){return new c_label();}
virtual void on_paint();
protected:
virtual void pre_create_wnd();
-private:
};
#endif
diff --git a/workspace/widgets_include/list_box.h b/workspace/widgets_include/list_box.h
index 2382ce2..8890643 100644
--- a/workspace/widgets_include/list_box.h
+++ b/workspace/widgets_include/list_box.h
@@ -16,12 +16,12 @@ public:
void select_item(short index);
protected:
- virtual c_wnd* clone(){return new c_list_box();}
virtual void pre_create_wnd();
virtual void on_paint();
virtual void on_focus();
virtual void on_kill_focus();
- virtual bool on_touch(int x, int y, TOUCH_ACTION action);
+ virtual void on_key(KEY_TYPE key);
+ virtual void on_touch(int x, int y, TOUCH_ACTION action);
private:
void update_list_size();
diff --git a/workspace/widgets_include/slide_group.h b/workspace/widgets_include/slide_group.h
index da7be96..3334173 100644
--- a/workspace/widgets_include/slide_group.h
+++ b/workspace/widgets_include/slide_group.h
@@ -13,14 +13,10 @@ public:
int add_slide(c_wnd* slide, unsigned short resource_id, short x, short y,
short width, short height, WND_TREE* p_child_tree = 0,
Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0);
- int add_clone_silde(c_wnd* slide, unsigned short resource_id, short x, short y,
- short width, short height, WND_TREE* p_child_tree = 0,
- Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0);
void disabel_all_slide();
- virtual bool on_touch(int x, int y, TOUCH_ACTION action);
- virtual bool on_key(KEY_TYPE key);
+ virtual void on_touch(int x, int y, TOUCH_ACTION action);
+ virtual void on_key(KEY_TYPE key);
protected:
- virtual c_wnd* clone(){return new c_slide_group();}
c_wnd* m_slides[MAX_PAGES];
int m_active_slide_index;
c_gesture* m_gesture;
diff --git a/workspace/widgets_include/spinbox.h b/workspace/widgets_include/spinbox.h
index 74be52d..0428e3c 100644
--- a/workspace/widgets_include/spinbox.h
+++ b/workspace/widgets_include/spinbox.h
@@ -1,63 +1,47 @@
#ifndef GUILITE_WIDGETS_INCLUDE_SPINBOX_H
#define GUILITE_WIDGETS_INCLUDE_SPINBOX_H
-#define GL_SPIN_CONFIRM 0x2222
#define GL_SPIN_CHANGE 0x3333
-#define ON_SPIN_CONFIRM(func) \
-{MSG_TYPE_WND, GL_SPIN_CONFIRM, 0, msgCallback(&func)},
-
#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
+{
+ friend class c_spin_box;
+ virtual void on_touch(int x, int y, TOUCH_ACTION action);
+ c_spin_box* m_spin_box;
+};
+
class c_spin_box : public c_wnd
{
+ friend class c_spin_button;
public:
- short get_value(){return m_value;}
- void set_value(unsigned short value){m_value = m_cur_value = value;}
+ short get_value() { return m_value; }
+ void set_value(unsigned short value) { m_value = m_cur_value = value; }
+ void set_max_min(short max, short min) { m_max = max; m_min = min; }
+ void set_step(short step) { m_step = step; }
+ short get_min() { return m_min; }
+ short get_max() { return m_max; }
+ short get_step() { return m_step; }
+ void set_value_digit(short digit) { m_digit = digit; }
+ short get_value_digit() { return m_digit; }
- void set_max_min(short max, short min){m_max = max; m_min = min;}
- void set_step(short step){m_step = step;}
-
- short get_min(){return m_min;}
- short get_max(){return m_max;}
- short get_step(){return m_step;}
-
- void set_value_digit(short digit){m_digit = digit;}
- short get_value_digit(){return m_digit;}
-
protected:
- virtual c_wnd* clone(){return new c_spin_box();}
virtual void on_paint();
- virtual void on_focus();
- virtual void on_kill_focus();
virtual void pre_create_wnd();
- virtual bool on_touch(int x, int y, TOUCH_ACTION action);
+ void on_arrow_up_bt_click();
+ void on_arrow_down_bt_click();
- void on_arrow_bt_click(int ctr_id, int param);
- void on_arrow_up_bt_click(int ctr_id, int param);
- void on_arrow_down_bt_click(int ctr_id, int param);
-
- GL_DECLARE_MESSAGE_MAP()
-
-private:
- void show_arrow_button();
- void hide_arrow_button();
- void on_touch_down(int x, int y);
- void on_touch_up(int x, int y);
-
-protected:
short m_cur_value;
short m_value;
short m_step;
short m_max;
short m_min;
short m_digit;
-
- c_button m_bt_up;
- c_button m_bt_down;
- c_rect m_bt_up_rect;
- c_rect m_bt_down_rect;
+ c_spin_button m_bt_up;
+ c_spin_button m_bt_down;
};
#endif
diff --git a/workspace/widgets_include/table.h b/workspace/widgets_include/table.h
index 065738f..59da5cf 100644
--- a/workspace/widgets_include/table.h
+++ b/workspace/widgets_include/table.h
@@ -7,7 +7,6 @@
class c_table: public c_wnd
{
public:
- virtual c_wnd* clone(){return new c_table();}
void set_sheet_align(unsigned int align_type){ m_align_type = align_type;}
void set_row_num(unsigned int row_num){ m_row_num = row_num;}
void set_col_num(unsigned int col_num){ m_col_num = col_num;}
@@ -22,6 +21,7 @@ public:
unsigned int get_col_num(){ return m_col_num;}
c_rect get_item_rect(int row, int col);
protected:
+ virtual void pre_create_wnd();
void draw_item(int row, int col, const char* str, unsigned int color);
unsigned int m_align_type;
diff --git a/workspace/widgets_include/wave_ctrl.h b/workspace/widgets_include/wave_ctrl.h
index 2d4c1a7..be0b47c 100644
--- a/workspace/widgets_include/wave_ctrl.h
+++ b/workspace/widgets_include/wave_ctrl.h
@@ -12,7 +12,6 @@ class c_wave_ctrl : public c_wnd
{
public:
c_wave_ctrl();
- virtual c_wnd* clone(){return new c_wave_ctrl();}
virtual void on_init_children();
virtual void on_paint();