From 8a77ba553dcd4cb7014436e5659ca41e5448b1be Mon Sep 17 00:00:00 2001 From: idea4good Date: Fri, 24 May 2019 15:16:03 +0800 Subject: [PATCH] support modal/non-modal dialog --- core/wnd.cpp | 2 +- core_include/wnd.h | 3 +-- widgets/dialog.cpp | 4 ++-- widgets/edit.cpp | 6 +++--- widgets/list_box.cpp | 6 +++--- widgets/spinbox.cpp | 4 ++-- widgets_include/button.h | 1 - widgets_include/dialog.h | 2 +- widgets_include/edit.h | 1 - 9 files changed, 13 insertions(+), 16 deletions(-) diff --git a/core/wnd.cpp b/core/wnd.cpp index 80731f7..d6027a8 100644 --- a/core/wnd.cpp +++ b/core/wnd.cpp @@ -477,7 +477,7 @@ bool c_wnd::on_touch(int x, int y, TOUCH_ACTION action) if (GL_ATTR_VISIBLE == (child->m_style & GL_ATTR_VISIBLE)) { child->get_wnd_rect(rect); - if (TRUE == rect.PtInRect(x, y) || child->m_style & GL_ATTR_PRIORITY) + if (TRUE == rect.PtInRect(x, y) || child->m_style & GL_ATTR_MODAL) { if (TRUE == child->is_focus_wnd()) { diff --git a/core_include/wnd.h b/core_include/wnd.h index fba16a9..0cfff5c 100644 --- a/core_include/wnd.h +++ b/core_include/wnd.h @@ -5,7 +5,7 @@ #define GL_ATTR_VISIBLE 0x80000000L #define GL_ATTR_DISABLED 0x40000000L #define GL_ATTR_FOCUS 0x20000000L -#define GL_ATTR_PRIORITY 0x10000000L// Handle touch action at high priority +#define GL_ATTR_MODAL 0x10000000L// Handle touch action at high priority typedef struct struct_font_info FONT_INFO; typedef struct struct_color_rect COLOR_RECT; @@ -52,7 +52,6 @@ class c_wnd : public c_cmd_target public: c_wnd(); virtual ~c_wnd() {}; - virtual const char* get_class_name() const { return "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 = NULL); virtual c_wnd* connect_clone(c_wnd *parent, unsigned short resource_id, const char* str, diff --git a/widgets/dialog.cpp b/widgets/dialog.cpp index 65e734d..900e37f 100644 --- a/widgets/dialog.cpp +++ b/widgets/dialog.cpp @@ -41,7 +41,7 @@ c_dialog* c_dialog::get_the_dialog(c_surface* surface) return NULL; } -int c_dialog::open_dialog(c_dialog* p_dlg) +int c_dialog::open_dialog(c_dialog* p_dlg, bool modal_mode) { if (NULL == p_dlg) { @@ -63,7 +63,7 @@ int c_dialog::open_dialog(c_dialog* p_dlg) p_dlg->get_screen_rect(rc); p_dlg->get_surface()->set_frame_layer(rc, Z_ORDER_LEVEL_1); - p_dlg->set_style(GL_ATTR_VISIBLE | GL_ATTR_FOCUS | GL_ATTR_PRIORITY); + p_dlg->set_style(modal_mode ? (GL_ATTR_VISIBLE | GL_ATTR_FOCUS | GL_ATTR_MODAL) : (GL_ATTR_VISIBLE | GL_ATTR_FOCUS)); p_dlg->show_window(); p_dlg->set_me_the_dialog(); return 1; diff --git a/widgets/edit.cpp b/widgets/edit.cpp index 838e948..423fe93 100644 --- a/widgets/edit.cpp +++ b/widgets/edit.cpp @@ -124,7 +124,7 @@ void c_edit::on_paint() s_keyboard.disconnect(); m_surface->set_frame_layer(empty_rect, s_keyboard.get_z_order()); m_z_order = m_parent->get_z_order(); - m_style &= ~GL_ATTR_PRIORITY; + m_style &= ~GL_ATTR_MODAL; } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); break; @@ -134,7 +134,7 @@ void c_edit::on_paint() s_keyboard.disconnect(); m_surface->set_frame_layer(empty_rect, s_keyboard.get_z_order()); m_z_order = m_parent->get_z_order(); - m_style &= ~GL_ATTR_PRIORITY; + m_style &= ~GL_ATTR_MODAL; } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); break; @@ -142,7 +142,7 @@ void c_edit::on_paint() if (m_z_order == m_parent->get_z_order()) { m_z_order++; - m_style |= GL_ATTR_PRIORITY; + m_style |= GL_ATTR_MODAL; show_keyboard(); } 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()); diff --git a/widgets/list_box.cpp b/widgets/list_box.cpp index d7b77cd..f196392 100644 --- a/widgets/list_box.cpp +++ b/widgets/list_box.cpp @@ -48,7 +48,7 @@ void c_list_box::on_paint() { m_surface->set_frame_layer(empty_rect, m_z_order); m_z_order = m_parent->get_z_order(); - m_style &= ~GL_ATTR_PRIORITY; + m_style &= ~GL_ATTR_MODAL; } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); break; @@ -57,7 +57,7 @@ void c_list_box::on_paint() { m_surface->set_frame_layer(empty_rect, m_z_order); m_z_order = m_parent->get_z_order(); - m_style &= ~GL_ATTR_PRIORITY; + m_style &= ~GL_ATTR_MODAL; } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); break; @@ -73,7 +73,7 @@ void c_list_box::on_paint() m_z_order++; } m_surface->set_frame_layer(m_list_screen_rect, m_z_order); - m_style |= GL_ATTR_PRIORITY; + m_style |= GL_ATTR_MODAL; show_list(); return; } diff --git a/widgets/spinbox.cpp b/widgets/spinbox.cpp index 464cdf1..fa3be70 100644 --- a/widgets/spinbox.cpp +++ b/widgets/spinbox.cpp @@ -103,14 +103,14 @@ void c_spin_box::show_arrow_button() m_bt_down.connect(this, ID_BT_ARROW_DOWN, "\xe2\x96\xbc"/*▼*/, 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_style |= GL_ATTR_PRIORITY; + m_style |= GL_ATTR_MODAL; } void c_spin_box::hide_arrow_button() { m_bt_up.disconnect(); m_bt_down.disconnect(); - m_style &= ~GL_ATTR_PRIORITY; + m_style &= ~GL_ATTR_MODAL; } void c_spin_box::on_paint() diff --git a/widgets_include/button.h b/widgets_include/button.h index b1a511a..259ab2f 100644 --- a/widgets_include/button.h +++ b/widgets_include/button.h @@ -9,7 +9,6 @@ typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { public: - virtual const char* get_class_name() const {return "c_button";} virtual c_wnd* clone(){return new c_button();} void set_bitmap(const BITMAP_INFO *pBitmap) { m_bitmap_normal = pBitmap; } diff --git a/widgets_include/dialog.h b/widgets_include/dialog.h index b524cb6..84b56e5 100644 --- a/widgets_include/dialog.h +++ b/widgets_include/dialog.h @@ -13,7 +13,7 @@ typedef struct class c_dialog : public c_wnd { public: - static int open_dialog(c_dialog* p_dlg); + static int open_dialog(c_dialog* p_dlg, bool modal_mode = true); static int close_dialog(c_surface* surface); static c_dialog* get_the_dialog(c_surface* surface); protected: diff --git a/widgets_include/edit.h b/widgets_include/edit.h index d32a116..5c0caad 100644 --- a/widgets_include/edit.h +++ b/widgets_include/edit.h @@ -10,7 +10,6 @@ class c_edit : public c_wnd friend class c_keyboard; public: virtual c_wnd* clone(){return new c_edit();} - virtual const char* get_class_name() const {return "c_edit";} const char* get_text(){return m_str;} void set_text(const char* str);