2017-12-13 22:29:28 +08:00
|
|
|
#include "core_include/api.h"
|
|
|
|
#include "core_include/rect.h"
|
|
|
|
#include "core_include/cmd_target.h"
|
|
|
|
#include "core_include/wnd.h"
|
2018-10-04 14:30:29 +08:00
|
|
|
#include "core_include/resource.h"
|
2017-12-13 22:29:28 +08:00
|
|
|
#include "core_include/word.h"
|
|
|
|
#include "core_include/surface.h"
|
2019-04-08 13:17:46 +08:00
|
|
|
#include "core_include/theme.h"
|
|
|
|
#include "../widgets_include/button.h"
|
|
|
|
#include "../widgets_include/label.h"
|
|
|
|
#include "../widgets_include/edit.h"
|
|
|
|
#include "../widgets_include/keyboard.h"
|
2017-12-06 21:43:47 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define IDD_ALL_KEY_BOARD 0x5012
|
|
|
|
#define IDD_NUM_KEY_BOARD 0x5013
|
|
|
|
|
2018-12-02 22:39:43 +08:00
|
|
|
GL_BEGIN_MESSAGE_MAP(c_edit)
|
2017-12-06 21:43:47 +08:00
|
|
|
ON_KEYBORAD_UPDATE(IDD_ALL_KEY_BOARD, c_edit::on_key_board_click)
|
|
|
|
ON_KEYBORAD_UPDATE(IDD_NUM_KEY_BOARD, c_edit::on_key_board_click)
|
2018-12-02 22:39:43 +08:00
|
|
|
GL_END_MESSAGE_MAP()
|
2017-12-06 21:43:47 +08:00
|
|
|
|
|
|
|
static c_keyboard s_keyboard;
|
|
|
|
|
|
|
|
void c_edit::pre_create_wnd()
|
|
|
|
{
|
2018-12-02 22:39:43 +08:00
|
|
|
m_style = GL_ATTR_VISIBLE | GL_ATTR_FOCUS | ALIGN_HCENTER | ALIGN_VCENTER | KEY_BOARD_STYLE;
|
2019-04-08 13:17:46 +08:00
|
|
|
m_font_type = c_theme::get_font(FONT_DEFAULT);
|
|
|
|
m_font_color = c_theme::get_color(COLOR_WND_FONT);
|
2017-12-06 21:43:47 +08:00
|
|
|
|
|
|
|
memset(m_str_input, 0, sizeof(m_str_input));
|
|
|
|
memset(m_str, 0, sizeof(m_str));
|
2019-05-24 10:20:40 +08:00
|
|
|
set_text(c_wnd::m_str);
|
2017-12-06 21:43:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void c_edit::set_text(const char* str)
|
|
|
|
{
|
|
|
|
if (str != NULL && strlen(str) < sizeof(m_str))
|
|
|
|
{
|
|
|
|
strcpy(m_str, str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:00:47 +08:00
|
|
|
bool 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;
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:43:47 +08:00
|
|
|
void c_edit::on_touch_down(int x, int y)
|
|
|
|
{
|
|
|
|
c_rect kb_rect_relate_2_edit_parent;
|
|
|
|
s_keyboard.get_wnd_rect(kb_rect_relate_2_edit_parent);
|
|
|
|
kb_rect_relate_2_edit_parent.m_left += m_wnd_rect.m_left;
|
|
|
|
kb_rect_relate_2_edit_parent.m_right += m_wnd_rect.m_left;
|
|
|
|
kb_rect_relate_2_edit_parent.m_top += m_wnd_rect.m_top;
|
|
|
|
kb_rect_relate_2_edit_parent.m_bottom += m_wnd_rect.m_top;
|
|
|
|
|
|
|
|
if (m_wnd_rect.PtInRect(x, y))
|
|
|
|
{//click edit box
|
|
|
|
if (STATUS_NORMAL == m_status)
|
|
|
|
{
|
2019-04-17 15:00:47 +08:00
|
|
|
m_parent->set_child_focus(this);
|
2017-12-06 21:43:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (kb_rect_relate_2_edit_parent.PtInRect(x,y))
|
|
|
|
{//click key board
|
2019-04-17 15:00:47 +08:00
|
|
|
c_wnd::on_touch(x, y, TOUCH_DOWN);
|
2017-12-06 21:43:47 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (STATUS_PUSHED == m_status)
|
|
|
|
{
|
2018-12-28 15:56:36 +08:00
|
|
|
m_status = STATUS_FOCUSED;
|
2017-12-06 21:43:47 +08:00
|
|
|
on_paint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void c_edit::on_touch_up(int x, int y)
|
|
|
|
{
|
|
|
|
if (STATUS_FOCUSED == m_status)
|
|
|
|
{
|
2018-12-28 15:56:36 +08:00
|
|
|
m_status = STATUS_PUSHED;
|
2017-12-06 21:43:47 +08:00
|
|
|
on_paint();
|
|
|
|
}
|
|
|
|
else if (STATUS_PUSHED == m_status)
|
|
|
|
{
|
|
|
|
if (m_wnd_rect.PtInRect(x,y))
|
|
|
|
{//click edit box
|
2018-12-28 15:56:36 +08:00
|
|
|
m_status = STATUS_FOCUSED;
|
2017-12-06 21:43:47 +08:00
|
|
|
on_paint();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-17 15:00:47 +08:00
|
|
|
c_wnd::on_touch(x, y, TOUCH_UP);
|
2017-12-06 21:43:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void c_edit::on_focus()
|
|
|
|
{
|
2018-12-28 15:56:36 +08:00
|
|
|
m_status = STATUS_FOCUSED;
|
2017-12-06 21:43:47 +08:00
|
|
|
on_paint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void c_edit::on_kill_focus()
|
|
|
|
{
|
2018-12-28 15:56:36 +08:00
|
|
|
m_status = STATUS_NORMAL;
|
2017-12-06 21:43:47 +08:00
|
|
|
on_paint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void c_edit::on_paint()
|
|
|
|
{
|
|
|
|
c_rect rect;
|
|
|
|
get_screen_rect(rect);
|
|
|
|
c_rect empty_rect;
|
|
|
|
empty_rect.Empty();
|
|
|
|
switch(m_status)
|
|
|
|
{
|
2018-10-04 14:30:29 +08:00
|
|
|
case STATUS_NORMAL:
|
2017-12-06 21:43:47 +08:00
|
|
|
if (m_z_order > m_parent->get_z_order())
|
|
|
|
{
|
|
|
|
s_keyboard.disconnect();
|
|
|
|
m_surface->set_frame_layer(empty_rect, s_keyboard.get_z_order());
|
|
|
|
m_z_order = m_parent->get_z_order();
|
2019-05-24 10:20:40 +08:00
|
|
|
m_style &= ~GL_ATTR_PRIORITY;
|
2017-12-06 21:43:47 +08:00
|
|
|
}
|
2019-04-08 13:17:46 +08:00
|
|
|
m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order);
|
2017-12-06 21:43:47 +08:00
|
|
|
break;
|
2018-10-04 14:30:29 +08:00
|
|
|
case STATUS_FOCUSED:
|
2017-12-06 21:43:47 +08:00
|
|
|
if (m_z_order > m_parent->get_z_order())
|
|
|
|
{
|
|
|
|
s_keyboard.disconnect();
|
|
|
|
m_surface->set_frame_layer(empty_rect, s_keyboard.get_z_order());
|
|
|
|
m_z_order = m_parent->get_z_order();
|
2019-05-24 10:20:40 +08:00
|
|
|
m_style &= ~GL_ATTR_PRIORITY;
|
2017-12-06 21:43:47 +08:00
|
|
|
}
|
2019-04-08 13:17:46 +08:00
|
|
|
m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order);
|
2018-10-04 14:30:29 +08:00
|
|
|
break;
|
|
|
|
case STATUS_PUSHED:
|
|
|
|
if (m_z_order == m_parent->get_z_order())
|
|
|
|
{
|
|
|
|
m_z_order++;
|
2019-05-24 10:20:40 +08:00
|
|
|
m_style |= GL_ATTR_PRIORITY;
|
2018-10-04 14:30:29 +08:00
|
|
|
show_keyboard();
|
|
|
|
}
|
2019-04-08 13:17:46 +08:00
|
|
|
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);
|
2017-12-06 21:43:47 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ASSERT(FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(m_str_input))
|
|
|
|
{
|
2018-11-01 10:35:37 +08:00
|
|
|
c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_style);
|
2017-12-06 21:43:47 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-01 10:35:37 +08:00
|
|
|
c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_style);
|
2017-12-06 21:43:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void c_edit::show_keyboard()
|
|
|
|
{
|
|
|
|
if (s_keyboard.get_id())
|
|
|
|
{
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((get_style()&KEY_BOARD_STYLE) == KEY_BOARD_STYLE )
|
|
|
|
{
|
|
|
|
s_keyboard.set_style(STYLE_ALL_BOARD);
|
2018-12-28 15:56:36 +08:00
|
|
|
s_keyboard.connect(this, IDD_ALL_KEY_BOARD);
|
2017-12-06 21:43:47 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_keyboard.set_style(STYLE_NUM_BOARD);
|
2018-12-28 15:56:36 +08:00
|
|
|
s_keyboard.connect(this, IDD_NUM_KEY_BOARD);
|
2017-12-06 21:43:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
c_rect kb_rect;
|
|
|
|
s_keyboard.get_screen_rect(kb_rect);
|
|
|
|
m_surface->set_frame_layer(kb_rect, s_keyboard.get_z_order());
|
|
|
|
s_keyboard.show_window();
|
|
|
|
}
|
|
|
|
|
|
|
|
void c_edit::on_key_board_click(unsigned int ctrl_id, long param)
|
|
|
|
{
|
|
|
|
switch (param)
|
|
|
|
{
|
|
|
|
case CLICK_CHAR:
|
|
|
|
strcpy(m_str_input, s_keyboard.get_str());
|
|
|
|
on_paint();
|
|
|
|
break;
|
|
|
|
case CLICK_ENTER:
|
|
|
|
if (strlen(m_str_input))
|
|
|
|
{
|
|
|
|
memcpy(m_str, m_str_input, sizeof(m_str_input));
|
|
|
|
}
|
2018-12-28 15:56:36 +08:00
|
|
|
m_status = STATUS_FOCUSED;
|
2017-12-06 21:43:47 +08:00
|
|
|
on_paint();
|
|
|
|
break;
|
|
|
|
case CLICK_ESC:
|
|
|
|
memset(m_str_input, 0, sizeof(m_str_input));
|
2018-12-28 15:56:36 +08:00
|
|
|
m_status = STATUS_FOCUSED;
|
2017-12-06 21:43:47 +08:00
|
|
|
on_paint();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ASSERT(FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|