diff --git a/include/nana/gui/basis.hpp b/include/nana/gui/basis.hpp index b868a00a..e6ee771c 100644 --- a/include/nana/gui/basis.hpp +++ b/include/nana/gui/basis.hpp @@ -24,10 +24,11 @@ namespace nana { namespace detail { - struct native_window_handle_impl{}; - struct window_handle_impl{}; - struct event_handle_impl{}; - struct native_drawable_impl{}; + struct basic_window; + + struct native_window_handle_impl; + struct native_drawable_impl; + struct event_handle_impl; } struct accel_key @@ -87,10 +88,11 @@ namespace nana struct root_tag : public widget_tag{ static const flags value = flags::root; }; }// end namespace category - using native_window_type = detail::native_window_handle_impl*; - using window = detail::window_handle_impl*; ///< \see [What is window class ](https://sourceforge.net/p/nanapro/discussion/general/thread/bd0fabfb/) - using event_handle = detail::event_handle_impl*; - using native_drawable_type = detail::native_drawable_impl*; + using window = detail::basic_window*; ///< The window handle type representing nana window objects + using native_window_type = detail::native_window_handle_impl*; ///< The native window handle type representing system native windows. E.g, HWND in windows, Window in X11 + + using event_handle = detail::event_handle_impl*; ///< The event handle type representing nana window events + using native_drawable_type = detail::native_drawable_impl*; ///< The drawable handle type representing system native drawable objects. E.g. HDC in windows, Drawable in X11 struct keyboard diff --git a/include/nana/gui/detail/effects_renderer.hpp b/include/nana/gui/detail/effects_renderer.hpp deleted file mode 100644 index 3a980caa..00000000 --- a/include/nana/gui/detail/effects_renderer.hpp +++ /dev/null @@ -1,223 +0,0 @@ -/* -* Effects Renderer -* Nana C++ Library(http://www.nanapro.org) -* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) -* -* Distributed under the Boost Software License, Version 1.0. -* (See accompanying file LICENSE_1_0.txt or copy at -* http://www.boost.org/LICENSE_1_0.txt) -* -* @file: nana/gui/detail/effects_renderer.cpp -*/ - -#ifndef NANA_GUI_DETAIL_EFFECTS_RENDERER_HPP -#define NANA_GUI_DETAIL_EFFECTS_RENDERER_HPP -#include -#include -#include -#include -#include - -namespace nana{ - namespace detail - { - template - class edge_nimbus_renderer - { - edge_nimbus_renderer() = default; - public: - using core_window_t = CoreWindow; - using window_layer = ::nana::detail::window_layout; - using graph_reference = ::nana::paint::graphics&; - - static edge_nimbus_renderer& instance() - { - static edge_nimbus_renderer object; - return object; - } - - constexpr unsigned weight() const - { - return 2; - } - - void erase(core_window_t* wd) - { - if (effects::edge_nimbus::none == wd->effect.edge_nimbus) - return; - - core_window_t * root_wd = wd->root_widget; - auto & nimbus = root_wd->other.attribute.root->effects_edge_nimbus; - - for (auto i = nimbus.begin(); i != nimbus.end(); ++i) - { - if (i->window == wd) - { - auto pixels = weight(); - rectangle r{wd->pos_root, wd->dimension}; - r.x -= static_cast(pixels); - r.y -= static_cast(pixels); - r.width += static_cast(pixels << 1); - r.height += static_cast(pixels << 1); - - root_wd->root_graph->paste(root_wd->root, r, r.x, r.y); - - nimbus.erase(i); - break; - } - } - } - - void render(core_window_t * wd, bool forced, const rectangle* update_area = nullptr) - { - bool copy_separately = true; - std::vector> rd_set; - - if (wd->root_widget->other.attribute.root->effects_edge_nimbus.size()) - { - auto root_wd = wd->root_widget; - - auto & nimbus = root_wd->other.attribute.root->effects_edge_nimbus; - - auto focused = root_wd->other.attribute.root->focus; - - const unsigned pixels = weight(); - - auto graph = root_wd->root_graph; - - nana::rectangle r; - for(auto & action : nimbus) - { - if(_m_edge_nimbus(action.window, focused) && window_layer::read_visual_rectangle(action.window, r)) - { - if (action.window == wd) - { - if (update_area) - ::nana::overlap(*update_area, rectangle(r), r); - copy_separately = false; - } - - //Avoiding duplicated rendering. If the window is declared to lazy refresh, it should be rendered. - if ((forced && (action.window == wd)) || (focused == action.window) || !action.rendered || (action.window->other.upd_state == core_window_t::update_state::refreshed)) - { - rd_set.emplace_back(r, action.window); - action.rendered = true; - } - } - else if(action.rendered) - { - action.rendered = false; - - if (action.window == wd) - copy_separately = false; - - ::nana::rectangle erase_r( - action.window->pos_root.x - static_cast(pixels), - action.window->pos_root.y - static_cast(pixels), - static_cast(action.window->dimension.width + (pixels << 1)), - static_cast(action.window->dimension.height + (pixels << 1)) - ); - - graph->paste(root_wd->root, erase_r, erase_r.x, erase_r.y); - } - } - } - - if (copy_separately) - { - rectangle vr; - if (window_layer::read_visual_rectangle(wd, vr)) - { - if (update_area) - ::nana::overlap(*update_area, rectangle(vr), vr); - wd->root_graph->paste(wd->root, vr, vr.x, vr.y); - } - } - - rectangle wd_r{ wd->pos_root, wd->dimension }; - wd_r.pare_off(-static_cast(this->weight())); - //Render - for (auto & rd : rd_set) - { - auto other_wd = rd.second; - - if (other_wd != wd) - { - rectangle other_r{ other_wd->pos_root, other_wd->dimension }; - other_r.pare_off(-static_cast(this->weight())); - if (!overlapped(wd_r, other_r)) - continue; - } - _m_render_edge_nimbus(other_wd, rd.first); - } - } - private: - /// Determines whether the effect will be rendered for the given window. - static bool _m_edge_nimbus(core_window_t * const wd, core_window_t * const focused_wd) - { - // Don't render the effect if the window is disabled. - if (wd->flags.enabled) - { - if ((focused_wd == wd) && (static_cast(wd->effect.edge_nimbus) & static_cast(effects::edge_nimbus::active))) - return true; - else if ((static_cast(wd->effect.edge_nimbus) & static_cast(effects::edge_nimbus::over)) && (wd->flags.action == mouse_action::hovered)) - return true; - } - return false; - } - - void _m_render_edge_nimbus(core_window_t* wd, const nana::rectangle & visual) - { - wd->flags.action_before = wd->flags.action; - - auto r = visual; - r.pare_off(-static_cast(weight())); - rectangle good_r; - if (overlap(r, rectangle{ wd->root_graph->size() }, good_r)) - { - if ((good_r.x < wd->pos_root.x) || (good_r.y < wd->pos_root.y) || - (good_r.right() > visual.right()) || (good_r.bottom() > visual.bottom())) - { - auto graph = wd->root_graph; - nana::paint::pixel_buffer pixbuf(graph->handle(), r); - - pixel_argb_t px0, px1, px2, px3; - - px0 = pixbuf.pixel(0, 0); - px1 = pixbuf.pixel(r.width - 1, 0); - px2 = pixbuf.pixel(0, r.height - 1); - px3 = pixbuf.pixel(r.width - 1, r.height - 1); - - good_r.x = good_r.y = 1; - good_r.width = r.width - 2; - good_r.height = r.height - 2; - pixbuf.rectangle(good_r, wd->annex.scheme->activated.get_color(), 0.95, false); - - good_r.x = good_r.y = 0; - good_r.width = r.width; - good_r.height = r.height; - pixbuf.rectangle(good_r, wd->annex.scheme->activated.get_color(), 0.4, false); - - pixbuf.pixel(0, 0, px0); - pixbuf.pixel(r.width - 1, 0, px1); - pixbuf.pixel(0, r.height - 1, px2); - pixbuf.pixel(r.width - 1, r.height - 1, px3); - - pixbuf.paste(wd->root, { r.x, r.y }); - - std::vector overlaps; - if(window_layer::read_overlaps(wd, visual, overlaps)) - { - for(auto & wdr : overlaps) - graph->paste(wd->root, wdr.r, wdr.r.x, wdr.r.y); - } - } - else - wd->root_graph->paste(wd->root, visual, visual.x, visual.y); - } - } - }; - } -}//end namespace nana - -#endif diff --git a/include/nana/gui/detail/general_events.hpp b/include/nana/gui/detail/general_events.hpp index 2171cb7a..f58f9680 100644 --- a/include/nana/gui/detail/general_events.hpp +++ b/include/nana/gui/detail/general_events.hpp @@ -24,9 +24,13 @@ namespace nana { + namespace API + { + bool is_window(window); ///< Determines whether a window is existing, equal to !empty_window. + } + namespace detail { - bool check_window(window); void events_operation_register(event_handle); class event_interface @@ -36,16 +40,16 @@ namespace nana virtual void remove(event_handle) = 0; }; - class docker_interface + class event_docker_interface { public: - virtual ~docker_interface() = default; + virtual ~event_docker_interface() = default; virtual event_interface* get_event() const = 0; }; struct docker_base - : public docker_interface + : public event_docker_interface { event_interface * const event_ptr; bool flag_deleted; @@ -78,11 +82,11 @@ namespace nana event_base * const evt_; }; - event_handle _m_emplace(detail::docker_interface*, bool in_front); + event_handle _m_emplace(detail::event_docker_interface*, bool in_front); protected: unsigned emitting_count_{ 0 }; bool deleted_flags_{ false }; - std::vector * dockers_{ nullptr }; + std::vector * dockers_{ nullptr }; }; }//end namespace detail @@ -228,7 +232,7 @@ namespace nana d->invoke(arg); - if (window_handle && (!detail::check_window(window_handle))) + if (window_handle && (!::nana::API::is_window(window_handle))) break; } } diff --git a/source/gui/detail/basic_window.cpp b/source/gui/detail/basic_window.cpp index 661e3619..bb585f49 100644 --- a/source/gui/detail/basic_window.cpp +++ b/source/gui/detail/basic_window.cpp @@ -10,7 +10,7 @@ * @file: nana/gui/detail/basic_window.cpp */ -#include +#include "basic_window.hpp" #include namespace nana diff --git a/include/nana/gui/detail/basic_window.hpp b/source/gui/detail/basic_window.hpp similarity index 96% rename from include/nana/gui/detail/basic_window.hpp rename to source/gui/detail/basic_window.hpp index bc0a116f..3d53eab5 100644 --- a/include/nana/gui/detail/basic_window.hpp +++ b/source/gui/detail/basic_window.hpp @@ -14,11 +14,11 @@ #ifndef NANA_GUI_DETAIL_BASIC_WINDOW_HPP #define NANA_GUI_DETAIL_BASIC_WINDOW_HPP #include -#include "drawer.hpp" -#include "events_holder.hpp" -#include "widget_geometrics.hpp" -#include "widget_content_measurer_interface.hpp" -#include "widget_notifier_interface.hpp" +#include +#include +#include +#include +#include #include #include #include diff --git a/source/gui/detail/bedrock_pi.cpp b/source/gui/detail/bedrock_pi.cpp index fdb1181b..a247a973 100644 --- a/source/gui/detail/bedrock_pi.cpp +++ b/source/gui/detail/bedrock_pi.cpp @@ -11,16 +11,17 @@ */ #include "../../detail/platform_spec_selector.hpp" +#include "basic_window.hpp" #include "bedrock_types.hpp" #include #include -#include #include #include -#include #include #include #include + +#include #include namespace nana @@ -64,11 +65,6 @@ namespace nana namespace detail { - bool check_window(window wd) - { - return bedrock::instance().wd_manager().available(reinterpret_cast(wd)); - } - void events_operation_register(event_handle evt) { bedrock::instance().evt_operation().register_evt(evt); @@ -171,7 +167,7 @@ namespace nana arg_expose arg; arg.exposed = exposed; - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; if (emit(event_code::expose, wd, arg, false, get_thread_context())) { //Get the window who has the activated caret @@ -203,7 +199,7 @@ namespace nana if (wd) { arg_move arg; - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; arg.x = x; arg.y = y; emit(event_code::move, wd, arg, true, get_thread_context()); @@ -218,7 +214,7 @@ namespace nana arg_mouse arg; arg.evt_code = event_code::mouse_leave; - arg.window_handle = reinterpret_cast(hovered); + arg.window_handle = hovered; arg.pos.x = arg.pos.y = 0; arg.left_button = arg.right_button = arg.mid_button = false; arg.ctrl = arg.shift = false; @@ -234,7 +230,7 @@ namespace nana auto focused = root_wd->other.attribute.root->focus; arg_focus arg; - arg.window_handle = reinterpret_cast(focused); + arg.window_handle = focused; arg.getting = getting; arg.receiver = receiver; @@ -416,7 +412,7 @@ namespace nana wd->drawer.click(*arg, bForce__EmitInternal); } if (bProcess__External_event) - evts_ptr->click.emit(*arg, reinterpret_cast(wd)); + evts_ptr->click.emit(*arg, wd); } } break; @@ -471,7 +467,7 @@ namespace nana } if (bProcess__External_event) - evt_addr->emit(*arg, reinterpret_cast(wd)); + evt_addr->emit(*arg, wd); break; } case event_code::mouse_wheel: @@ -486,7 +482,7 @@ namespace nana } if (bProcess__External_event) - evts_ptr->mouse_wheel.emit(*arg, reinterpret_cast(wd)); + evts_ptr->mouse_wheel.emit(*arg, wd); } break; } @@ -530,7 +526,7 @@ namespace nana } if (bProcess__External_event) - evt_addr->emit(*arg, reinterpret_cast(wd)); + evt_addr->emit(*arg, wd); break; } case event_code::expose: @@ -538,7 +534,7 @@ namespace nana { auto arg = dynamic_cast(&event_arg); if (arg) - evts_ptr->expose.emit(*arg, reinterpret_cast(wd)); + evts_ptr->expose.emit(*arg, wd); } break; case event_code::focus: @@ -552,7 +548,7 @@ namespace nana wd->drawer.focus(*arg, bForce__EmitInternal); } if (bProcess__External_event) - evts_ptr->focus.emit(*arg, reinterpret_cast(wd)); + evts_ptr->focus.emit(*arg, wd); } break; } @@ -567,7 +563,7 @@ namespace nana wd->drawer.move(*arg, bForce__EmitInternal); } if (bProcess__External_event) - evts_ptr->move.emit(*arg, reinterpret_cast(wd)); + evts_ptr->move.emit(*arg, wd); } break; } @@ -582,7 +578,7 @@ namespace nana wd->drawer.resizing(*arg, bForce__EmitInternal); } if (bProcess__External_event) - evts_ptr->resizing.emit(*arg, reinterpret_cast(wd)); + evts_ptr->resizing.emit(*arg, wd); } break; } @@ -597,7 +593,7 @@ namespace nana wd->drawer.resized(*arg, bForce__EmitInternal); } if (bProcess__External_event) - evts_ptr->resized.emit(*arg, reinterpret_cast(wd)); + evts_ptr->resized.emit(*arg, wd); } break; } @@ -609,7 +605,7 @@ namespace nana { auto evt_root = dynamic_cast(evts_ptr); if (evt_root) - evt_root->unload.emit(*arg, reinterpret_cast(wd)); + evt_root->unload.emit(*arg, wd); } } break; @@ -618,7 +614,7 @@ namespace nana { auto arg = dynamic_cast(&event_arg); if (arg) - evts_ptr->destroy.emit(*arg, reinterpret_cast(wd)); + evts_ptr->destroy.emit(*arg, wd); } break; default: diff --git a/source/gui/detail/bedrock_posix.cpp b/source/gui/detail/bedrock_posix.cpp index 699e7380..69c49efa 100644 --- a/source/gui/detail/bedrock_posix.cpp +++ b/source/gui/detail/bedrock_posix.cpp @@ -143,7 +143,7 @@ namespace detail void bedrock::flush_surface(core_window_t* wd, bool forced, const rectangle* update_area) { - wd->drawer.map(reinterpret_cast(wd), forced, update_area); + wd->drawer.map(wd, forced, update_area); } //inc_window @@ -255,7 +255,7 @@ namespace detail void assign_arg(arg_mouse& arg, basic_window* wd, unsigned msg, const XEvent& evt) { - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; arg.button = ::nana::mouse::any_button; int mask_state = 0; @@ -308,7 +308,7 @@ namespace detail void assign_arg(arg_focus& arg, basic_window* wd, native_window_type recv, bool getting) { - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; arg.receiver = recv; arg.getting = getting; arg.focus_reason = arg_focus::reason::general; @@ -317,7 +317,7 @@ namespace detail void assign_arg(arg_wheel& arg, basic_window* wd, const XEvent& evt) { arg.evt_code = event_code::mouse_wheel; - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; if (ButtonRelease == evt.type && (evt.xbutton.button == Button4 || evt.xbutton.button == Button5)) { arg.evt_code = event_code::mouse_wheel; @@ -371,12 +371,12 @@ namespace detail if(msgwd) { arg_dropfiles arg; - arg.window_handle = reinterpret_cast(msgwd); + arg.window_handle = msgwd; arg.files.swap(*msg.u.mouse_drop.files); delete msg.u.mouse_drop.files; arg.pos.x = msg.u.mouse_drop.x - msgwd->pos_root.x; arg.pos.y = msg.u.mouse_drop.y - msgwd->pos_root.y; - msgwd->annex.events_ptr->mouse_dropfiles.emit(arg, reinterpret_cast(msgwd)); + msgwd->annex.events_ptr->mouse_dropfiles.emit(arg, msgwd); brock.wd_manager().do_lazy_refresh(msgwd, false); } break; @@ -539,15 +539,15 @@ namespace detail auto shr_wd = wd_manager.find_shortkey(native_window, arg.key); if(shr_wd) { - arg.window_handle = reinterpret_cast(shr_wd); + arg.window_handle = shr_wd; brock.emit(event_code::shortkey, shr_wd, arg, true, &context); } continue; } arg.evt_code = event_code::key_char; - arg.window_handle = reinterpret_cast(msgwd); - msgwd->annex.events_ptr->key_char.emit(arg, reinterpret_cast(msgwd)); + arg.window_handle = msgwd; + msgwd->annex.events_ptr->key_char.emit(arg, msgwd); if(arg.ignore == false && wd_manager.available(msgwd)) draw_invoker(&drawer::key_char, msgwd, arg, &context); } @@ -789,7 +789,7 @@ namespace detail { msgwnd->set_action(mouse_action::hovered); - click_arg.window_handle = reinterpret_cast(msgwnd); + click_arg.window_handle = msgwnd; draw_invoker(&drawer::click, msgwnd, click_arg, &context); } } @@ -807,16 +807,16 @@ namespace detail draw_invoker(&drawer::mouse_up, msgwnd, arg, &context); if(click_arg.window_handle) - evt_ptr->click.emit(click_arg, reinterpret_cast(msgwnd)); + evt_ptr->click.emit(click_arg, msgwnd); if (wd_manager.available(msgwnd)) { arg.evt_code = event_code::mouse_up; - evt_ptr->mouse_up.emit(arg, reinterpret_cast(msgwnd)); + evt_ptr->mouse_up.emit(arg, msgwnd); } } else if(click_arg.window_handle) - msgwnd->annex.events_ptr->click.emit(click_arg, reinterpret_cast(msgwnd)); + msgwnd->annex.events_ptr->click.emit(click_arg, msgwnd); wd_manager.do_lazy_refresh(msgwnd, false); } @@ -940,7 +940,7 @@ namespace detail //Don't copy root_graph to the window directly, otherwise the edge nimbus effect will be missed. ::nana::rectangle update_area(xevent.xexpose.x, xevent.xexpose.y, xevent.xexpose.width, xevent.xexpose.height); if (!update_area.empty()) - msgwnd->drawer.map(reinterpret_cast(msgwnd), true, &update_area); + msgwnd->drawer.map(msgwnd, true, &update_area); } } break; @@ -1030,7 +1030,7 @@ namespace detail arg.mid_button = false; arg.pos.x = 0; arg.pos.y = 0; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; msgwnd->set_action(mouse_action::pressed); @@ -1052,7 +1052,7 @@ namespace detail bool focused = (brock.focus() == msgwnd); arg_keyboard arg; arg.evt_code = event_code::key_press; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; arg.ignore = false; arg.key = os_code; brock.get_key_state(arg); @@ -1074,7 +1074,7 @@ namespace detail arg.ignore = false; arg.key = os_code; arg.evt_code = event_code::key_press; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; brock.emit(event_code::key_press, msgwnd, arg, true, &context); @@ -1130,7 +1130,7 @@ namespace detail arg_click click_arg; click_arg.mouse_args = nullptr; - click_arg.window_handle = reinterpret_cast(msgwnd); + click_arg.window_handle = msgwnd; arg_mouse arg; arg.alt = false; @@ -1141,7 +1141,7 @@ namespace detail arg.mid_button = false; arg.pos.x = 0; arg.pos.y = 0; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; draw_invoker(&drawer::mouse_up, msgwnd, arg, &context); @@ -1155,7 +1155,7 @@ namespace detail arg_keyboard arg; arg.evt_code = event_code::key_release; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; arg.ignore = false; arg.key = os_code; brock.get_key_state(arg); @@ -1181,7 +1181,7 @@ namespace detail arg_keyboard arg; arg.evt_code = event_code::key_release; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; arg.ignore = false; arg.key = os_code; brock.get_key_state(arg); @@ -1208,7 +1208,7 @@ namespace detail if(msgwnd->flags.enabled && (atoms.wm_delete_window == static_cast(xclient.data.l[0]))) { arg_unload arg; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; arg.cancel = false; brock.emit(event_code::unload, msgwnd, arg, true, &context); if(false == arg.cancel) @@ -1262,7 +1262,7 @@ namespace detail core_window_t * owner = 0; if(condition_wd && is_modal) { - native_window_type modal = reinterpret_cast(condition_wd)->root; + native_window_type modal = condition_wd->root; owner_native = native_interface::get_window(modal, window_relationship::owner); if(owner_native) { @@ -1273,7 +1273,7 @@ namespace detail } } - nana::detail::platform_spec::instance().msg_dispatch(condition_wd ? reinterpret_cast(condition_wd)->root : 0); + nana::detail::platform_spec::instance().msg_dispatch(condition_wd ? condition_wd->root : 0); if(owner_native) { diff --git a/source/gui/detail/bedrock_windows.cpp b/source/gui/detail/bedrock_windows.cpp index a84d9e61..3765571f 100644 --- a/source/gui/detail/bedrock_windows.cpp +++ b/source/gui/detail/bedrock_windows.cpp @@ -311,7 +311,7 @@ namespace detail } } else - wd->drawer.map(reinterpret_cast(wd), forced, update_area); + wd->drawer.map(wd, forced, update_area); } void interior_helper_for_menu(MSG& msg, native_window_type menu_window) @@ -367,7 +367,7 @@ namespace detail MSG msg; if (condition_wd) { - HWND native_handle = reinterpret_cast(reinterpret_cast(condition_wd)->root); + HWND native_handle = reinterpret_cast(condition_wd->root); if (is_modal) { HWND owner = ::GetWindow(native_handle, GW_OWNER); @@ -466,7 +466,7 @@ namespace detail void assign_arg(nana::arg_mouse& arg, basic_window* wd, unsigned msg, const parameter_decoder& pmdec) { - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; bool set_key_state = true; switch (msg) @@ -530,7 +530,7 @@ namespace detail void assign_arg(arg_wheel& arg, basic_window* wd, const parameter_decoder& pmdec) { - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; arg.evt_code = event_code::mouse_wheel; POINT point = { pmdec.mouse.x, pmdec.mouse.y }; @@ -985,7 +985,7 @@ namespace detail msgwnd->set_action(mouse_action::hovered); if ((::nana::mouse::left_button == arg.button) && (pressed_wd == msgwnd)) { - click_arg.window_handle = reinterpret_cast(msgwnd); + click_arg.window_handle = msgwnd; draw_invoker(&drawer::click, msgwnd, click_arg, &context); } } @@ -997,16 +997,16 @@ namespace detail draw_invoker(&drawer::mouse_up, msgwnd, arg, &context); if (click_arg.window_handle) - retain->click.emit(click_arg, reinterpret_cast(msgwnd)); + retain->click.emit(click_arg, msgwnd); if (wd_manager.available(msgwnd)) { arg.evt_code = event_code::mouse_up; - retain->mouse_up.emit(arg, reinterpret_cast(msgwnd)); + retain->mouse_up.emit(arg, msgwnd); } } else if (click_arg.window_handle) - retain->click.emit(click_arg, reinterpret_cast(msgwnd)); + retain->click.emit(click_arg, msgwnd); wd_manager.do_lazy_refresh(msgwnd, false); } @@ -1176,9 +1176,9 @@ namespace detail dropfiles.pos = pos; wd_manager.calc_window_point(msgwnd, dropfiles.pos); - dropfiles.window_handle = reinterpret_cast(msgwnd); + dropfiles.window_handle = msgwnd; - msgwnd->annex.events_ptr->mouse_dropfiles.emit(dropfiles, reinterpret_cast(msgwnd)); + msgwnd->annex.events_ptr->mouse_dropfiles.emit(dropfiles, msgwnd); wd_manager.do_lazy_refresh(msgwnd, false); } } @@ -1232,7 +1232,7 @@ namespace detail static_cast(r->bottom - r->top - msgwnd->extra_height)); arg_resizing arg; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; arg.width = size_before.width; arg.height = size_before.height; @@ -1285,7 +1285,7 @@ namespace detail //Don't copy root_graph to the window directly, otherwise the edge nimbus effect will be missed. ::nana::rectangle update_area(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right - ps.rcPaint.left, ps.rcPaint.bottom - ps.rcPaint.top); if (!update_area.empty()) - msgwnd->drawer.map(reinterpret_cast(msgwnd), true, &update_area); + msgwnd->drawer.map(msgwnd, true, &update_area); } ::EndPaint(root_window, &ps); } @@ -1300,7 +1300,7 @@ namespace detail arg.evt_code = event_code::shortkey; arg.key = static_cast(wParam < 0x61 ? wParam + 0x61 - 0x41 : wParam); arg.ctrl = arg.shift = false; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; arg.ignore = false; brock.emit(event_code::shortkey, msgwnd, arg, true, &context); def_window_proc = false; @@ -1316,7 +1316,7 @@ namespace detail bool focused = (brock.focus() == msgwnd); arg_keyboard arg; arg.evt_code = event_code::key_press; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; arg.ignore = false; arg.key = static_cast(wParam); brock.get_key_state(arg); @@ -1344,7 +1344,7 @@ namespace detail arg_keyboard arg; arg.evt_code = event_code::key_release; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; arg.ignore = false; arg.key = static_cast(wParam); brock.get_key_state(arg); @@ -1397,7 +1397,7 @@ namespace detail arg.mid_button = false; arg.pos.x = 0; arg.pos.y = 0; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; msgwnd->set_action(mouse_action::pressed); @@ -1412,7 +1412,7 @@ namespace detail { arg_keyboard arg; arg.evt_code = event_code::key_press; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; arg.ignore = false; arg.key = translate_virtual_key(wParam); brock.get_key_state(arg); @@ -1443,12 +1443,12 @@ namespace detail { arg_keyboard arg; arg.evt_code = event_code::key_char; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; arg.key = static_cast(wParam); brock.get_key_state(arg); arg.ignore = false; - msgwnd->annex.events_ptr->key_char.emit(arg, reinterpret_cast(msgwnd)); + msgwnd->annex.events_ptr->key_char.emit(arg, msgwnd); if ((false == arg.ignore) && wd_manager.available(msgwnd)) draw_invoker(&drawer::key_char, msgwnd, arg, &context); @@ -1476,7 +1476,7 @@ namespace detail arg_click click_arg; click_arg.mouse_args = nullptr; - click_arg.window_handle = reinterpret_cast(msgwnd); + click_arg.window_handle = msgwnd; arg_mouse arg; arg.alt = false; @@ -1487,7 +1487,7 @@ namespace detail arg.mid_button = false; arg.pos.x = 0; arg.pos.y = 0; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; draw_invoker(&drawer::mouse_up, msgwnd, arg, &context); @@ -1500,7 +1500,7 @@ namespace detail { arg_keyboard keyboard_arg; keyboard_arg.evt_code = event_code::key_release; - keyboard_arg.window_handle = reinterpret_cast(msgwnd); + keyboard_arg.window_handle = msgwnd; keyboard_arg.key = translate_virtual_key(wParam); brock.get_key_state(keyboard_arg); keyboard_arg.ignore = false; @@ -1521,7 +1521,7 @@ namespace detail case WM_CLOSE: { arg_unload arg; - arg.window_handle = reinterpret_cast(msgwnd); + arg.window_handle = msgwnd; arg.cancel = false; brock.emit(event_code::unload, msgwnd, arg, true, &context); if (!arg.cancel) @@ -1742,9 +1742,6 @@ namespace detail void bedrock::undefine_state_cursor(core_window_t * wd, thread_context* thrd) { - if (nullptr == thrd) - thrd = get_thread_context(wd->thread_id); - HCURSOR rev_handle = ::LoadCursor(nullptr, IDC_ARROW); if (!wd_manager().available(wd)) { @@ -1753,6 +1750,9 @@ namespace detail return; } + if (nullptr == thrd) + thrd = get_thread_context(wd->thread_id); + wd->root_widget->other.attribute.root->state_cursor = nana::cursor::arrow; wd->root_widget->other.attribute.root->state_cursor_window = nullptr; diff --git a/source/gui/detail/drawer.cpp b/source/gui/detail/drawer.cpp index da5b0091..379d53b6 100644 --- a/source/gui/detail/drawer.cpp +++ b/source/gui/detail/drawer.cpp @@ -10,11 +10,11 @@ * @file: nana/gui/detail/drawer.cpp */ +#include "basic_window.hpp" +#include "effects_renderer.hpp" #include #include #include -#include -#include #include "dynamic_drawing_object.hpp" #if defined(NANA_X11) @@ -23,8 +23,6 @@ namespace nana { - typedef detail::edge_nimbus_renderer edge_nimbus_renderer_t; - //class drawer_trigger void drawer_trigger::attached(widget_reference, graph_reference){} void drawer_trigger::detached(){} //none-const @@ -360,7 +358,7 @@ namespace nana #endif } - edge_nimbus_renderer_t::instance().render(iwd, forced, update_area); + edge_nimbus_renderer::instance().render(iwd, forced, update_area); if(owns_caret) { @@ -475,4 +473,192 @@ namespace nana return data_impl_->mth_state[pos]; } }//end namespace detail + + namespace detail + { + //class edge_nimbus_renderer + edge_nimbus_renderer& edge_nimbus_renderer::instance() + { + static edge_nimbus_renderer object; + return object; + } + + void edge_nimbus_renderer::erase(basic_window* wd) + { + if (effects::edge_nimbus::none == wd->effect.edge_nimbus) + return; + + auto root_wd = wd->root_widget; + auto & nimbus = root_wd->other.attribute.root->effects_edge_nimbus; + + for (auto i = nimbus.begin(); i != nimbus.end(); ++i) + { + if (i->window == wd) + { + auto pixels = weight(); + rectangle r{ wd->pos_root, wd->dimension }; + r.x -= static_cast(pixels); + r.y -= static_cast(pixels); + r.width += static_cast(pixels << 1); + r.height += static_cast(pixels << 1); + + root_wd->root_graph->paste(root_wd->root, r, r.x, r.y); + + nimbus.erase(i); + break; + } + } + } + + void edge_nimbus_renderer::render(basic_window* wd, bool forced, const rectangle* update_area) + { + bool copy_separately = true; + std::vector> rd_set; + + if (wd->root_widget->other.attribute.root->effects_edge_nimbus.size()) + { + auto root_wd = wd->root_widget; + + auto & nimbus = root_wd->other.attribute.root->effects_edge_nimbus; + + auto focused = root_wd->other.attribute.root->focus; + + const unsigned pixels = weight(); + + auto graph = root_wd->root_graph; + + nana::rectangle r; + for (auto & action : nimbus) + { + if (_m_edge_nimbus(action.window, focused) && window_layer::read_visual_rectangle(action.window, r)) + { + if (action.window == wd) + { + if (update_area) + ::nana::overlap(*update_area, rectangle(r), r); + copy_separately = false; + } + + //Avoiding duplicated rendering. If the window is declared to lazy refresh, it should be rendered. + if ((forced && (action.window == wd)) || (focused == action.window) || !action.rendered || (action.window->other.upd_state == basic_window::update_state::refreshed)) + { + rd_set.emplace_back(r, action.window); + action.rendered = true; + } + } + else if (action.rendered) + { + action.rendered = false; + + if (action.window == wd) + copy_separately = false; + + ::nana::rectangle erase_r( + action.window->pos_root.x - static_cast(pixels), + action.window->pos_root.y - static_cast(pixels), + static_cast(action.window->dimension.width + (pixels << 1)), + static_cast(action.window->dimension.height + (pixels << 1)) + ); + + graph->paste(root_wd->root, erase_r, erase_r.x, erase_r.y); + } + } + } + + if (copy_separately) + { + rectangle vr; + if (window_layer::read_visual_rectangle(wd, vr)) + { + if (update_area) + ::nana::overlap(*update_area, rectangle(vr), vr); + wd->root_graph->paste(wd->root, vr, vr.x, vr.y); + } + } + + rectangle wd_r{ wd->pos_root, wd->dimension }; + wd_r.pare_off(-static_cast(this->weight())); + //Render + for (auto & rd : rd_set) + { + auto other_wd = rd.second; + + if (other_wd != wd) + { + rectangle other_r{ other_wd->pos_root, other_wd->dimension }; + other_r.pare_off(-static_cast(this->weight())); + if (!overlapped(wd_r, other_r)) + continue; + } + _m_render_edge_nimbus(other_wd, rd.first); + } + } + + /// Determines whether the effect will be rendered for the given window. + bool edge_nimbus_renderer::_m_edge_nimbus(basic_window * const wd, basic_window * const focused_wd) + { + // Don't render the effect if the window is disabled. + if (wd->flags.enabled) + { + if ((focused_wd == wd) && (static_cast(wd->effect.edge_nimbus) & static_cast(effects::edge_nimbus::active))) + return true; + else if ((static_cast(wd->effect.edge_nimbus) & static_cast(effects::edge_nimbus::over)) && (wd->flags.action == mouse_action::hovered)) + return true; + } + return false; + } + + void edge_nimbus_renderer::_m_render_edge_nimbus(basic_window* wd, const nana::rectangle & visual) + { + wd->flags.action_before = wd->flags.action; + + auto r = visual; + r.pare_off(-static_cast(weight())); + rectangle good_r; + if (overlap(r, rectangle{ wd->root_graph->size() }, good_r)) + { + if ((good_r.x < wd->pos_root.x) || (good_r.y < wd->pos_root.y) || + (good_r.right() > visual.right()) || (good_r.bottom() > visual.bottom())) + { + auto graph = wd->root_graph; + nana::paint::pixel_buffer pixbuf(graph->handle(), r); + + pixel_argb_t px0, px1, px2, px3; + + px0 = pixbuf.pixel(0, 0); + px1 = pixbuf.pixel(r.width - 1, 0); + px2 = pixbuf.pixel(0, r.height - 1); + px3 = pixbuf.pixel(r.width - 1, r.height - 1); + + good_r.x = good_r.y = 1; + good_r.width = r.width - 2; + good_r.height = r.height - 2; + pixbuf.rectangle(good_r, wd->annex.scheme->activated.get_color(), 0.95, false); + + good_r.x = good_r.y = 0; + good_r.width = r.width; + good_r.height = r.height; + pixbuf.rectangle(good_r, wd->annex.scheme->activated.get_color(), 0.4, false); + + pixbuf.pixel(0, 0, px0); + pixbuf.pixel(r.width - 1, 0, px1); + pixbuf.pixel(0, r.height - 1, px2); + pixbuf.pixel(r.width - 1, r.height - 1, px3); + + pixbuf.paste(wd->root, { r.x, r.y }); + + std::vector overlaps; + if (window_layer::read_overlaps(wd, visual, overlaps)) + { + for (auto & wdr : overlaps) + graph->paste(wd->root, wdr.r, wdr.r.x, wdr.r.y); + } + } + else + wd->root_graph->paste(wd->root, visual, visual.x, visual.y); + } + } + + //end class edge_nimbus_renderer + }//end namespace detail }//end namespace nana diff --git a/source/gui/detail/effects_renderer.hpp b/source/gui/detail/effects_renderer.hpp new file mode 100644 index 00000000..99fbf49c --- /dev/null +++ b/source/gui/detail/effects_renderer.hpp @@ -0,0 +1,52 @@ +/* +* Effects Renderer +* Nana C++ Library(http://www.nanapro.org) +* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com) +* +* Distributed under the Boost Software License, Version 1.0. +* (See accompanying file LICENSE_1_0.txt or copy at +* http://www.boost.org/LICENSE_1_0.txt) +* +* @file: nana/gui/detail/effects_renderer.cpp +*/ + +#ifndef NANA_GUI_DETAIL_EFFECTS_RENDERER_HPP +#define NANA_GUI_DETAIL_EFFECTS_RENDERER_HPP +#include "basic_window.hpp" +#include +#include +#include +#include +#include + +namespace nana{ + namespace detail + { + /// Effect edige nimbus renderer + class edge_nimbus_renderer + { + edge_nimbus_renderer() = default; + public: + using window_layer = ::nana::detail::window_layout; + using graph_reference = ::nana::paint::graphics&; + + static edge_nimbus_renderer& instance(); + + constexpr unsigned weight() const + { + return 2; + } + + void erase(basic_window* wd); + + void render(basic_window* wd, bool forced, const rectangle* update_area = nullptr); + private: + /// Determines whether the effect will be rendered for the given window. + static bool _m_edge_nimbus(basic_window * const wd, basic_window * const focused_wd); + + void _m_render_edge_nimbus(basic_window* wd, const nana::rectangle & visual); + }; + } +}//end namespace nana + +#endif diff --git a/source/gui/detail/events_operation.cpp b/source/gui/detail/events_operation.cpp index a278bc96..9c7c12dc 100644 --- a/source/gui/detail/events_operation.cpp +++ b/source/gui/detail/events_operation.cpp @@ -26,9 +26,7 @@ namespace nana auto i = handles_.find(evt); if (i != handles_.end()) - { - reinterpret_cast(evt)->get_event()->remove(evt); - } + reinterpret_cast(evt)->get_event()->remove(evt); } //end namespace events_operation @@ -80,35 +78,33 @@ namespace nana void event_base::remove(event_handle evt) { internal_scope_guard lock; - if (dockers_) + + for (auto i = dockers_->begin(), end = dockers_->end(); i != end; ++i) { - for (auto i = dockers_->begin(), end = dockers_->end(); i != end; ++i) + if (reinterpret_cast(evt) == *i) { - if (reinterpret_cast(evt) == *i) + //Checks whether this event is working now. + if (emitting_count_) { - //Checks whether this event is working now. - if (emitting_count_) - { - static_cast(*i)->flag_deleted = true; - deleted_flags_ = true; - } - else - { - bedrock::instance().evt_operation().cancel(evt); - dockers_->erase(i); - delete reinterpret_cast(evt); - } - break; + static_cast(*i)->flag_deleted = true; + deleted_flags_ = true; } + else + { + bedrock::instance().evt_operation().cancel(evt); + dockers_->erase(i); + delete reinterpret_cast(evt); + } + return; } } } - event_handle event_base::_m_emplace(detail::docker_interface* docker_ptr, bool in_front) + event_handle event_base::_m_emplace(detail::event_docker_interface* docker_ptr, bool in_front) { internal_scope_guard lock; if (nullptr == dockers_) - dockers_ = new std::vector; + dockers_ = new std::vector; auto evt = reinterpret_cast(docker_ptr); diff --git a/source/gui/detail/inner_fwd_implement.hpp b/source/gui/detail/inner_fwd_implement.hpp index 5c66323c..af246905 100644 --- a/source/gui/detail/inner_fwd_implement.hpp +++ b/source/gui/detail/inner_fwd_implement.hpp @@ -15,8 +15,8 @@ #define NANA_GUI_INNER_FWD_IMPLEMENT_HPP #include +#include "basic_window.hpp" #include -#include #include #include diff --git a/source/gui/detail/window_layout.cpp b/source/gui/detail/window_layout.cpp index b0187eec..db8b3bb8 100644 --- a/source/gui/detail/window_layout.cpp +++ b/source/gui/detail/window_layout.cpp @@ -11,8 +11,8 @@ * */ +#include "basic_window.hpp" #include -#include #include #include #include @@ -286,7 +286,7 @@ namespace nana } if (wd->effect.bground) - wd->effect.bground->take_effect(reinterpret_cast(wd), glass_buffer); + wd->effect.bground->take_effect(wd, glass_buffer); } void window_layout::_m_paste_children(core_window_t* wd, bool have_refreshed, bool req_refresh_children, const nana::rectangle& parent_rect, nana::paint::graphics& graph, const nana::point& graph_rpos) diff --git a/source/gui/detail/window_manager.cpp b/source/gui/detail/window_manager.cpp index 9f854ee4..4464766d 100644 --- a/source/gui/detail/window_manager.cpp +++ b/source/gui/detail/window_manager.cpp @@ -18,7 +18,8 @@ #include #include #include -#include + +#include "effects_renderer.hpp" #include "window_register.hpp" #include "inner_fwd_implement.hpp" @@ -587,7 +588,7 @@ namespace detail { auto &brock = bedrock::instance(); arg_unload arg; - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; arg.cancel = false; brock.emit(event_code::unload, wd, arg, true, brock.get_thread_context()); if (false == arg.cancel) @@ -758,7 +759,7 @@ namespace detail auto &brock = bedrock::instance(); arg_move arg; - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; arg.x = x; arg.y = y; @@ -812,7 +813,7 @@ namespace detail wd->other.upd_state = basic_window::update_state::request_refresh; arg_move arg; - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; arg.x = r.x; arg.y = r.y; brock.emit(event_code::move, wd, arg, true, brock.get_thread_context()); @@ -846,7 +847,7 @@ namespace detail native_interface::move_window(wd->root, root_r); arg_resized arg; - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; arg.width = root_r.width; arg.height = root_r.height; brock.emit(event_code::resized, wd, arg, true, brock.get_thread_context()); @@ -875,7 +876,7 @@ namespace detail if (sz != wd->dimension) { arg_resizing arg; - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; arg.border = window_border::none; arg.width = sz.width; arg.height = sz.height; @@ -970,7 +971,7 @@ namespace detail } arg_resized arg; - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; arg.width = sz.width; arg.height = sz.height; brock.emit(event_code::resized, wd, arg, ask_update, brock.get_thread_context()); @@ -1177,7 +1178,7 @@ namespace detail prev_focus->annex.caret_ptr->activate(false); arg.getting = false; - arg.window_handle = reinterpret_cast(prev_focus); + arg.window_handle = prev_focus; arg.receiver = wd->root; arg.focus_reason = arg_focus::reason::general; brock.emit(event_code::focus, prev_focus, arg, true, brock.get_thread_context()); @@ -1194,7 +1195,7 @@ namespace detail if(wd->annex.caret_ptr) wd->annex.caret_ptr->activate(true); - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; arg.getting = true; arg.receiver = wd->root; arg.focus_reason = reason; @@ -1444,7 +1445,7 @@ namespace detail if (impl_->wd_register.available(wd)) { //the root runtime must exist, because the wd is valid. Otherse, it's bug of library - return root_runtime(wd->root)->shortkeys.make(reinterpret_cast(wd), key); + return root_runtime(wd->root)->shortkeys.make(wd, key); } return false; } @@ -1458,7 +1459,7 @@ namespace detail auto root_rt = root_runtime(wd->root); if (root_rt) { - root_rt->shortkeys.umake(reinterpret_cast(wd)); + root_rt->shortkeys.umake(wd); if (with_children) { for (auto child : wd->children) @@ -1475,7 +1476,7 @@ namespace detail std::lock_guard lock(mutex_); auto object = root_runtime(native_window); if(object) - return reinterpret_cast(object->shortkeys.find(key)); + return object->shortkeys.find(key); } return nullptr; } @@ -1598,10 +1599,8 @@ namespace detail if (!established) { - using effect_renderer = detail::edge_nimbus_renderer; - //remove the window from edge nimbus effect when it is destroying - effect_renderer::instance().erase(wd); + edge_nimbus_renderer::instance().erase(wd); } else if (pa_root_attr != root_attr) { @@ -1705,13 +1704,11 @@ namespace detail wd->annex.caret_ptr = nullptr; } - using effect_renderer = detail::edge_nimbus_renderer; - //remove the window from edge nimbus effect when it is destroying - effect_renderer::instance().erase(wd); + edge_nimbus_renderer::instance().erase(wd); arg_destroy arg; - arg.window_handle = reinterpret_cast(wd); + arg.window_handle = wd; brock.emit(event_code::destroy, wd, arg, true, brock.get_thread_context()); //Delete the children widgets. @@ -1770,7 +1767,7 @@ namespace detail //The root_rt must exist, because wd is valid. Otherwise, it's a bug of the library. auto root_rt = root_runtime(wd->root); - auto pkeys = root_rt->shortkeys.keys(reinterpret_cast(wd)); + auto pkeys = root_rt->shortkeys.keys(wd); if (pkeys) { for (auto key : *pkeys) diff --git a/source/gui/detail/window_register.hpp b/source/gui/detail/window_register.hpp index 7a2500e4..965a1afa 100644 --- a/source/gui/detail/window_register.hpp +++ b/source/gui/detail/window_register.hpp @@ -1,7 +1,7 @@ #ifndef NANA_WINDOW_REGISTER_HEADER_INCLUDED #define NANA_WINDOW_REGISTER_HEADER_INCLUDED -#include +#include "basic_window.hpp" #include #include #include //std::find diff --git a/source/gui/dragdrop.cpp b/source/gui/dragdrop.cpp index 18f51e52..900d86c0 100644 --- a/source/gui/dragdrop.cpp +++ b/source/gui/dragdrop.cpp @@ -13,9 +13,9 @@ #include #include - #include -#include + +#include "detail/basic_window.hpp" #include #include @@ -961,8 +961,7 @@ namespace nana if (API::is_window(window_handle)) { dragging = true; - auto real_wd = reinterpret_cast(window_handle); - real_wd->other.dnd_state = dragdrop_status::not_ready; + window_handle->other.dnd_state = dragdrop_status::not_ready; } API::release_capture(window_handle); @@ -1000,9 +999,7 @@ namespace nana if (arg.is_left_button() && API::is_window(impl_->window_handle)) { impl_->dragging = ((!impl_->predicate) || impl_->predicate()); - - auto real_wd = reinterpret_cast(impl_->window_handle); - real_wd->other.dnd_state = dragdrop_status::ready; + impl_->window_handle->other.dnd_state = dragdrop_status::ready; } }); @@ -1010,14 +1007,13 @@ namespace nana if (!(arg.is_left_button() && impl_->dragging && API::is_window(arg.window_handle))) return; - auto real_wd = reinterpret_cast(arg.window_handle); - real_wd->other.dnd_state = dragdrop_status::in_progress; + arg.window_handle->other.dnd_state = dragdrop_status::in_progress; std::unique_ptr dropdata{new dragdrop_service::dropdata_type}; auto has_dropped = dragdrop_service::instance().dragdrop(arg.window_handle, dropdata.get(), nullptr); - real_wd->other.dnd_state = dragdrop_status::not_ready; + arg.window_handle->other.dnd_state = dragdrop_status::not_ready; impl_->dragging = false; if (has_dropped) @@ -1116,9 +1112,7 @@ namespace nana if (arg.is_left_button() && API::is_window(impl_->source_handle)) { impl_->dragging = ((!impl_->predicate) || impl_->predicate()); - - auto real_wd = reinterpret_cast(impl_->source_handle); - real_wd->other.dnd_state = dragdrop_status::ready; + impl_->source_handle->other.dnd_state = dragdrop_status::ready; } }); @@ -1126,13 +1120,9 @@ namespace nana if (!(arg.is_left_button() && impl_->dragging && API::is_window(arg.window_handle))) return; - auto real_wd = reinterpret_cast(arg.window_handle); - real_wd->other.dnd_state = dragdrop_status::in_progress; - + arg.window_handle->other.dnd_state = dragdrop_status::in_progress; impl_->make_drop(); - - - real_wd->other.dnd_state = dragdrop_status::not_ready; + arg.window_handle->other.dnd_state = dragdrop_status::not_ready; impl_->dragging = false; }); } diff --git a/source/gui/drawing.cpp b/source/gui/drawing.cpp index 2e6e2142..9b1fb7e6 100644 --- a/source/gui/drawing.cpp +++ b/source/gui/drawing.cpp @@ -10,9 +10,9 @@ * @file: nana/gui/drawing.cpp */ +#include "detail/basic_window.hpp" #include #include -#include namespace nana { @@ -22,11 +22,9 @@ namespace nana { namespace { - using core_window_t = detail::basic_window; - inline detail::drawer& get_drawer(window wd) { - return reinterpret_cast(wd)->drawer; + return wd->drawer; } } } @@ -38,7 +36,7 @@ namespace nana if (!API::is_window(wd)) throw std::invalid_argument("drawing: invalid window parameter"); - if (reinterpret_cast(wd)->is_draw_through()) + if (wd->is_draw_through()) throw std::invalid_argument("drawing: the window is draw_through enabled"); } @@ -46,7 +44,7 @@ namespace nana bool drawing::empty() const { - return API::empty_window(handle_) || reinterpret_cast(handle_)->root_graph->empty(); + return API::empty_window(handle_) || handle_->root_graph->empty(); } void drawing::update() const diff --git a/source/gui/programming_interface.cpp b/source/gui/programming_interface.cpp index 28b61836..2610e17e 100644 --- a/source/gui/programming_interface.cpp +++ b/source/gui/programming_interface.cpp @@ -11,9 +11,9 @@ * @author: Jinhao */ +#include "detail/basic_window.hpp" #include #include -#include #include #include #include @@ -81,104 +81,100 @@ namespace API bool emit_event(event_code evt_code, window wd, const ::nana::event_arg& arg) { - return restrict::bedrock.emit(evt_code, reinterpret_cast<::nana::detail::basic_window*>(wd), arg, true, restrict::bedrock.get_thread_context(), false); + return restrict::bedrock.emit(evt_code, wd, arg, true, restrict::bedrock.get_thread_context(), false); } bool emit_internal_event(event_code evt_code, window wd, const ::nana::event_arg& arg) { - return restrict::bedrock.emit(evt_code, reinterpret_cast<::nana::detail::basic_window*>(wd), arg, true, restrict::bedrock.get_thread_context(), true); + return restrict::bedrock.emit(evt_code, wd, arg, true, restrict::bedrock.get_thread_context(), true); } void enum_widgets_function_base::enum_widgets(window wd, bool recursive) { - auto iwd = reinterpret_cast(wd); - internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) + if (is_window(wd)) { - //Use a copy, because enum function may close a child window and the original children container would be changed, - //in the situation, the walking thorugh directly to the iwd->children would cause error. - auto children = iwd->children; + //Use a copy, because enumerating function may close a child window and the original children container would be changed, + //in the situation, the walking thorugh directly to the wd->children would cause error. + auto children = wd->children; for (auto child : children) { - auto widget_ptr = API::get_widget(reinterpret_cast(child)); + auto widget_ptr = API::get_widget(child); if (!widget_ptr) continue; _m_enum_fn(widget_ptr); if (recursive) - enum_widgets(reinterpret_cast(child), recursive); + enum_widgets(child, recursive); } } } general_events* get_general_events(window wd) { - if (!restrict::wd_manager().available(reinterpret_cast(wd))) + if (empty_window(wd)) return nullptr; - return reinterpret_cast(wd)->annex.events_ptr.get(); + return wd->annex.events_ptr.get(); } }//end namespace detail void effects_edge_nimbus(window wd, effects::edge_nimbus en) { - auto const iwd = reinterpret_cast(wd); - internal_scope_guard isg; - if(restrict::wd_manager().available(iwd)) + internal_scope_guard lock; + if(is_window(wd)) { - auto & cont = iwd->root_widget->other.attribute.root->effects_edge_nimbus; + auto & cont = wd->root_widget->other.attribute.root->effects_edge_nimbus; if(effects::edge_nimbus::none != en) { - if (iwd->effect.edge_nimbus == effects::edge_nimbus::none) + if (wd->effect.edge_nimbus == effects::edge_nimbus::none) { - cont.emplace_back(basic_window::edge_nimbus_action{ iwd, false}); + cont.emplace_back(basic_window::edge_nimbus_action{ wd, false}); } - iwd->effect.edge_nimbus = static_cast(static_cast(en) | static_cast(iwd->effect.edge_nimbus)); + wd->effect.edge_nimbus = static_cast(static_cast(en) | static_cast(wd->effect.edge_nimbus)); } else { - if(effects::edge_nimbus::none != iwd->effect.edge_nimbus) + if(effects::edge_nimbus::none != wd->effect.edge_nimbus) { for(auto i = cont.begin(); i != cont.end(); ++i) - if(i->window == iwd) + if(i->window == wd) { cont.erase(i); break; } } - iwd->effect.edge_nimbus = effects::edge_nimbus::none; + wd->effect.edge_nimbus = effects::edge_nimbus::none; } } } effects::edge_nimbus effects_edge_nimbus(window wd) { - auto const iwd = reinterpret_cast(wd); - internal_scope_guard isg; - return (restrict::wd_manager().available(iwd) ? iwd->effect.edge_nimbus : effects::edge_nimbus::none); + internal_scope_guard lock; + return (is_window(wd) ? wd->effect.edge_nimbus : effects::edge_nimbus::none); } void effects_bground(window wd, const effects::bground_factory_interface& factory, double fade_rate) { if (fade_rate < 0.0 || fade_rate > 1.0) throw std::invalid_argument("effects_bground: value range of fade_rate must be [0, 1]."); - auto const iwd = reinterpret_cast(wd); - internal_scope_guard isg; - if(restrict::wd_manager().available(iwd)) + + internal_scope_guard lock; + if(is_window(wd)) { auto new_effect_ptr = effects::effects_accessor::create(factory); if(nullptr == new_effect_ptr) return; - delete iwd->effect.bground; - iwd->effect.bground = new_effect_ptr; - iwd->effect.bground_fade_rate = fade_rate; - restrict::wd_manager().enable_effects_bground(iwd, true); + delete wd->effect.bground; + wd->effect.bground = new_effect_ptr; + wd->effect.bground_fade_rate = fade_rate; + restrict::wd_manager().enable_effects_bground(wd, true); if (fade_rate < 0.01) - iwd->flags.make_bground_declared = true; + wd->flags.make_bground_declared = true; API::refresh_window(wd); } @@ -192,21 +188,19 @@ namespace API bground_mode effects_bground_mode(window wd) { - auto const iwd = reinterpret_cast(wd); - internal_scope_guard isg; - if(restrict::wd_manager().available(iwd) && iwd->effect.bground) - return (iwd->effect.bground_fade_rate <= 0.009 ? bground_mode::basic : bground_mode::blend); + internal_scope_guard lock; + if(is_window(wd) && wd->effect.bground) + return (wd->effect.bground_fade_rate <= 0.009 ? bground_mode::basic : bground_mode::blend); return bground_mode::none; } void effects_bground_remove(window wd) { - const auto iwd = reinterpret_cast(wd); - internal_scope_guard isg; - if(restrict::wd_manager().available(iwd)) + internal_scope_guard lock; + if(is_window(wd)) { - if(restrict::wd_manager().enable_effects_bground(iwd, false)) + if(restrict::wd_manager().enable_effects_bground(wd, false)) API::refresh_window(wd); } } @@ -221,99 +215,92 @@ namespace API bool set_events(window wd, const std::shared_ptr& gep) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) - iwd->set_events(gep); + if (is_window(wd)) + return wd->set_events(gep); return false; } void set_scheme(window wd, widget_geometrics* wdg_geom) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) - iwd->annex.scheme = wdg_geom; + if (is_window(wd)) + wd->annex.scheme = wdg_geom; } widget_geometrics* get_scheme(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - return (restrict::wd_manager().available(iwd) ? iwd->annex.scheme : nullptr); + return (is_window(wd) ? wd->annex.scheme : nullptr); } void set_measurer(window wd, ::nana::dev::widget_content_measurer_interface* measurer) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) - iwd->annex.content_measurer = measurer; + if (is_window(wd)) + wd->annex.content_measurer = measurer; } - void attach_drawer(widget& wd, drawer_trigger& dr) + void attach_drawer(widget& wdg, drawer_trigger& dr) { - const auto iwd = reinterpret_cast(wd.handle()); - internal_scope_guard isg; - if(restrict::wd_manager().available(iwd)) + const auto wd = wdg.handle(); + internal_scope_guard lock; + if(is_window(wd)) { - iwd->drawer.graphics.make(iwd->dimension); - iwd->drawer.graphics.rectangle(true, iwd->annex.scheme->background.get_color()); - iwd->drawer.attached(wd, dr); - iwd->drawer.refresh(); //Always redraw no matter it is visible or invisible. This can make the graphics data correctly. + wd->drawer.graphics.make(wd->dimension); + wd->drawer.graphics.rectangle(true, wd->annex.scheme->background.get_color()); + wd->drawer.attached(wdg, dr); + wd->drawer.refresh(); //Always redraw no matter it is visible or invisible. This can make the graphics data correctly. } } ::nana::detail::native_string_type window_caption(window wd) noexcept { - auto const iwd = reinterpret_cast(wd); - internal_scope_guard isg; - - if(restrict::wd_manager().available(iwd)) + internal_scope_guard lock; + if(is_window(wd)) { - if (category::flags::root == iwd->other.category) - return interface_type::window_caption(iwd->root); - return iwd->title; + if (category::flags::root == wd->other.category) + return interface_type::window_caption(wd->root); + return wd->title; } return {}; } void window_caption(window wd, ::nana::detail::native_string_type title) { - auto const iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) + if (is_window(wd)) { - iwd->title.swap(title); - if (iwd->other.category == category::flags::root) - interface_type::window_caption(iwd->root, iwd->title); + wd->title.swap(title); + if (wd->other.category == category::flags::root) + interface_type::window_caption(wd->root, wd->title); - restrict::wd_manager().update(iwd, true, false); + refresh_window(wd); } } window create_window(window owner, bool nested, const rectangle& r, const appearance& ap, widget* wdg) { - return reinterpret_cast(restrict::wd_manager().create_root(reinterpret_cast(owner), nested, r, ap, wdg)); + return restrict::wd_manager().create_root(owner, nested, r, ap, wdg); } window create_widget(window parent, const rectangle& r, widget* wdg) { - return reinterpret_cast(restrict::wd_manager().create_widget(reinterpret_cast(parent), r, false, wdg)); + return restrict::wd_manager().create_widget(parent, r, false, wdg); } window create_lite_widget(window parent, const rectangle& r, widget* wdg) { - return reinterpret_cast(restrict::wd_manager().create_widget(reinterpret_cast(parent), r, true, wdg)); + return restrict::wd_manager().create_widget(parent, r, true, wdg); } paint::graphics* window_graphics(window wd) { - internal_scope_guard isg; - if(restrict::wd_manager().available(reinterpret_cast(wd))) - return &reinterpret_cast(wd)->drawer.graphics; + internal_scope_guard lock; + if(is_window(wd)) + return &(wd->drawer.graphics); return nullptr; } @@ -325,25 +312,24 @@ namespace API void register_menu_window(window wd, bool has_keyboard) { internal_scope_guard lock; - if (restrict::wd_manager().available(reinterpret_cast(wd))) - restrict::bedrock.set_menu(reinterpret_cast(wd)->root, has_keyboard); + if (is_window(wd)) + restrict::bedrock.set_menu(wd->root, has_keyboard); } void set_menubar(window wd, bool attach) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) + if (is_window(wd)) { - auto root_attr = iwd->root_widget->other.attribute.root; + auto root_attr = wd->root_widget->other.attribute.root; if (attach) { if (!root_attr->menubar) - root_attr->menubar = iwd; + root_attr->menubar = wd; } else { - if (iwd == root_attr->menubar) + if (wd == root_attr->menubar) root_attr->menubar = nullptr; } } @@ -351,35 +337,30 @@ namespace API void enable_space_click(window wd, bool enable) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) - iwd->flags.space_click_enabled = enable; + if (is_window(wd)) + wd->flags.space_click_enabled = enable; } bool copy_transparent_background(window wd, paint::graphics& graph) { - auto & buf = reinterpret_cast(wd)->other.glass_buffer; internal_scope_guard lock; if (bground_mode::basic != API::effects_bground_mode(wd)) return false; - buf.paste(rectangle{ buf.size() }, graph, 0, 0); - + wd->other.glass_buffer.paste(rectangle{ wd->other.glass_buffer.size() }, graph, 0, 0); return true; } bool copy_transparent_background(window wd, const rectangle& src_r, paint::graphics& graph, const point& dst_pt) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; if (bground_mode::basic != API::effects_bground_mode(wd)) return false; - iwd->other.glass_buffer.paste(src_r, graph, dst_pt.x, dst_pt.y); - + wd->other.glass_buffer.paste(src_r, graph, dst_pt.x, dst_pt.y); return true; } @@ -413,18 +394,16 @@ namespace API void window_draggable(window wd, bool enabled) { - auto real_wd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(real_wd)) - real_wd->flags.draggable = enabled; + if (is_window(wd)) + wd->flags.draggable = enabled; } bool window_draggable(window wd) { - auto real_wd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(real_wd)) - return real_wd->flags.draggable; + if (is_window(wd)) + return wd->flags.draggable; return false; } @@ -435,8 +414,8 @@ namespace API widget* get_widget(window wd) { internal_scope_guard lock; - if (restrict::wd_manager().available(reinterpret_cast(wd))) - return reinterpret_cast(wd)->widget_notifier->widget_ptr(); + if (is_window(wd)) + return wd->widget_notifier->widget_ptr(); return nullptr; } @@ -495,15 +474,15 @@ namespace API bool register_shortkey(window wd, unsigned long key) { - return restrict::wd_manager().register_shortkey(reinterpret_cast(wd), key); + return restrict::wd_manager().register_shortkey(wd, key); } void unregister_shortkey(window wd) { - restrict::wd_manager().unregister_shortkey(reinterpret_cast(wd), false); + restrict::wd_manager().unregister_shortkey(wd, false); } - ::nana::point cursor_position() + ::nana::point cursor_position() { return interface_type::cursor_position(); } @@ -536,37 +515,35 @@ namespace API void window_icon(window wd, const paint::image& small_icon, const paint::image& big_icon) { if(nullptr != wd) - restrict::wd_manager().icon(reinterpret_cast(wd), small_icon, big_icon); + restrict::wd_manager().icon(wd, small_icon, big_icon); } bool empty_window(window wd) { - return (restrict::wd_manager().available(reinterpret_cast(wd)) == false); + return (restrict::wd_manager().available(wd) == false); } bool is_window(window wd) { - return restrict::wd_manager().available(reinterpret_cast(wd)); + return restrict::wd_manager().available(wd); } bool is_destroying(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (!restrict::wd_manager().available(iwd)) + if (!restrict::wd_manager().available(wd)) return false; - return iwd->flags.destroying; + return wd->flags.destroying; } void enable_dropfiles(window wd, bool enb) { internal_scope_guard lock; - auto iwd = reinterpret_cast(wd); auto native_handle = API::root(wd); if (native_handle) { - iwd->flags.dropable = enb; + wd->flags.dropable = enb; interface_type::enable_dropfiles(native_handle, enb); } } @@ -580,88 +557,83 @@ namespace API { internal_scope_guard lock; if(is_window(wd)) - return reinterpret_cast(wd)->root; + return wd->root; return nullptr; } window root(native_window_type wd) { - return reinterpret_cast(restrict::wd_manager().root(wd)); + return restrict::wd_manager().root(wd); } void enable_double_click(window wd, bool dbl) { - auto const iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) - iwd->flags.dbl_click = dbl; + if(is_window(wd)) + wd->flags.dbl_click = dbl; } void fullscreen(window wd, bool v) { internal_scope_guard lock; - if(restrict::wd_manager().available(reinterpret_cast(wd))) - reinterpret_cast(wd)->flags.fullscreen = v; + if(is_window(wd)) + wd->flags.fullscreen = v; } void close_window(window wd) { - restrict::wd_manager().close(reinterpret_cast(wd)); + restrict::wd_manager().close(wd); } void show_window(window wd, bool show) { - restrict::wd_manager().show(reinterpret_cast(wd), show); + restrict::wd_manager().show(wd, show); } bool visible(window wd) { - auto const iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) + if(is_window(wd)) { - if(iwd->other.category == category::flags::root) - return interface_type::is_window_visible(iwd->root); - return iwd->visible; + if(wd->other.category == category::flags::root) + return interface_type::is_window_visible(wd->root); + return wd->visible; } return false; } void restore_window(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) + if(is_window(wd)) { - if(iwd->other.category == category::flags::root) - interface_type::restore_window(iwd->root); + if(wd->other.category == category::flags::root) + interface_type::restore_window(wd->root); } } void zoom_window(window wd, bool ask_for_max) { - auto core_wd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(core_wd)) + if(is_window(wd)) { - if(category::flags::root == core_wd->other.category) - interface_type::zoom_window(core_wd->root, ask_for_max); + if(category::flags::root == wd->other.category) + interface_type::zoom_window(wd->root, ask_for_max); } } window get_parent_window(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) + if (is_window(wd)) { - if (category::flags::root == iwd->other.category) + if (category::flags::root == wd->other.category) { - return reinterpret_cast(restrict::wd_manager().root( - interface_type::get_window(iwd->root, window_relationship::parent) - )); + return restrict::wd_manager().root( + interface_type::get_window(wd->root, window_relationship::parent) + ); } - return reinterpret_cast(iwd->parent); + return wd->parent; } return nullptr; @@ -669,13 +641,12 @@ namespace API window get_owner_window(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd) && (iwd->other.category == category::flags::root)) + if(is_window(wd) && (wd->other.category == category::flags::root)) { - auto owner = interface_type::get_window(iwd->root, window_relationship::owner); + auto owner = interface_type::get_window(wd->root, window_relationship::owner); if(owner) - return reinterpret_cast(restrict::wd_manager().root(owner)); + return restrict::wd_manager().root(owner); } return nullptr; @@ -683,7 +654,7 @@ namespace API bool set_parent_window(window wd, window new_parent) { - return restrict::wd_manager().set_parent(reinterpret_cast(wd), reinterpret_cast(new_parent)); + return restrict::wd_manager().set_parent(wd, new_parent); } void umake_event(event_handle eh) @@ -693,32 +664,30 @@ namespace API nana::point window_position(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) + if(is_window(wd)) { - return ( (iwd->other.category == category::flags::root) ? - interface_type::window_position(iwd->root) : iwd->pos_owner); + return ( (wd->other.category == category::flags::root) ? + interface_type::window_position(wd->root) : wd->pos_owner); } return nana::point{}; } void move_window(window wd, const point& pos) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().move(iwd, pos.x, pos.y, false)) + if(restrict::wd_manager().move(wd, pos.x, pos.y, false)) { basic_window* update_wd = nullptr; - if (iwd->displayed() && iwd->effect.bground) + if (wd->displayed() && wd->effect.bground) { - update_wd = iwd; - restrict::wd_manager().update(iwd, true, false); + update_wd = wd; + refresh_window(wd); } - basic_window* anc = iwd; - if (category::flags::root != iwd->other.category) - anc = iwd->seek_non_lite_widget_ancestor(); + basic_window* anc = wd; + if (category::flags::root != wd->other.category) + anc = wd->seek_non_lite_widget_ancestor(); if (anc != update_wd) restrict::wd_manager().update(anc, false, false); @@ -727,14 +696,13 @@ namespace API void move_window(window wd, const rectangle& r) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().move(iwd, r)) + if(restrict::wd_manager().move(wd, r)) { - if (category::flags::root != iwd->other.category) - iwd = iwd->seek_non_lite_widget_ancestor(); + if (category::flags::root != wd->other.category) + wd = wd->seek_non_lite_widget_ancestor(); - restrict::wd_manager().update(iwd, false, false); + restrict::wd_manager().update(wd, false, false); } } @@ -745,23 +713,21 @@ namespace API bool set_window_z_order(window wd, window wd_after, z_order_action action_if_no_wd_after) { - auto iwd = reinterpret_cast(wd); native_window_type native_after = nullptr; internal_scope_guard lock; - if (restrict::wd_manager().available(iwd) && (category::flags::root == iwd->other.category)) + if (is_window(wd) && (category::flags::root == wd->other.category)) { if(wd_after) { - auto iwd_after = reinterpret_cast(wd_after); - if (restrict::wd_manager().available(iwd_after) && (iwd_after->other.category == category::flags::root)) + if (is_window(wd_after) && (wd_after->other.category == category::flags::root)) { - native_after = iwd_after->root; + native_after = wd_after->root; action_if_no_wd_after = z_order_action::none; } else return false; } - interface_type::set_window_z_order(iwd->root, native_after, action_if_no_wd_after); + interface_type::set_window_z_order(wd->root, native_after, action_if_no_wd_after); return true; } return false; @@ -769,23 +735,21 @@ namespace API void draw_through(window wd, std::function draw_fn) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (!restrict::wd_manager().available(iwd)) + if (empty_window(wd)) throw std::invalid_argument("draw_through: invalid window parameter"); - if (::nana::category::flags::root != iwd->other.category) + if (::nana::category::flags::root != wd->other.category) throw std::invalid_argument("draw_through: the window is not a root widget"); - iwd->other.attribute.root->draw_through.swap(draw_fn); + wd->other.attribute.root->draw_through.swap(draw_fn); } void map_through_widgets(window wd, native_drawable_type drawable) { - auto iwd = reinterpret_cast<::nana::detail::basic_window*>(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd) && iwd->is_draw_through() ) - restrict::bedrock.map_through_widgets(iwd, drawable); + if (is_window(wd) && wd->is_draw_through() ) + restrict::bedrock.map_through_widgets(wd, drawable); } nana::size window_size(window wd) @@ -797,29 +761,27 @@ namespace API void window_size(window wd, const size& sz) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().size(iwd, sz, false, false)) + if(restrict::wd_manager().size(wd, sz, false, false)) { - if (category::flags::root != iwd->other.category) - iwd = iwd->seek_non_lite_widget_ancestor(); + if (category::flags::root != wd->other.category) + wd = wd->seek_non_lite_widget_ancestor(); - restrict::wd_manager().update(iwd, false, false); + restrict::wd_manager().update(wd, false, false); } } ::nana::size window_outline_size(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (!restrict::wd_manager().available(iwd)) + if (empty_window(wd)) return{}; auto sz = window_size(wd); - if(category::flags::root == iwd->other.category) + if(category::flags::root == wd->other.category) { - auto fm_extents = interface_type::window_frame_extents(iwd->root); + auto fm_extents = interface_type::window_frame_extents(wd->root); sz.width += fm_extents.left + fm_extents.right; sz.height += fm_extents.top + fm_extents.bottom; } @@ -829,13 +791,12 @@ namespace API void window_outline_size(window wd, const size& sz) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) + if (is_window(wd)) { - if (category::flags::root == iwd->other.category) + if (category::flags::root == wd->other.category) { - auto fm_extents = interface_type::window_frame_extents(iwd->root); + auto fm_extents = interface_type::window_frame_extents(wd->root); size inner_size = sz; @@ -858,20 +819,18 @@ namespace API std::optional window_rectangle(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) - return rectangle(iwd->pos_owner, iwd->dimension); + if (is_window(wd)) + return rectangle(wd->pos_owner, wd->dimension); return{}; } bool get_window_rectangle(window wd, rectangle& r) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) + if(is_window(wd)) { - r = rectangle(iwd->pos_owner, iwd->dimension); + r = rectangle(wd->pos_owner, wd->dimension); return true; } return false; @@ -879,28 +838,27 @@ namespace API bool track_window_size(window wd, const nana::size& sz, bool true_for_max) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd) == false) + if(is_window(wd) == false) return false; - nana::size & ts = (true_for_max ? iwd->max_track_size : iwd->min_track_size); + nana::size & ts = (true_for_max ? wd->max_track_size : wd->min_track_size); if(!sz.empty()) { if(true_for_max) { //Make sure the new size is larger than min size - if (iwd->min_track_size.width > sz.width || iwd->min_track_size.height > sz.height) + if (wd->min_track_size.width > sz.width || wd->min_track_size.height > sz.height) return false; } else { //Make sure that the new size is less than max size - if ((iwd->max_track_size.width || iwd->max_track_size.height) && (iwd->max_track_size.width < sz.width || iwd->max_track_size.height < sz.height)) + if ((wd->max_track_size.width || wd->max_track_size.height) && (wd->max_track_size.width < sz.width || wd->max_track_size.height < sz.height)) return false; } - ts = interface_type::check_track_size(sz, iwd->extra_width, iwd->extra_height, true_for_max); + ts = interface_type::check_track_size(sz, wd->extra_width, wd->extra_height, true_for_max); } else ts.width = ts.height = 0; @@ -909,155 +867,145 @@ namespace API void window_enabled(window wd, bool enabled) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd) && (iwd->flags.enabled != enabled)) + if(is_window(wd) && (wd->flags.enabled != enabled)) { - iwd->flags.enabled = enabled; - restrict::wd_manager().update(iwd, true, true); - if(category::flags::root == iwd->other.category) - interface_type::enable_window(iwd->root, enabled); + wd->flags.enabled = enabled; + restrict::wd_manager().update(wd, true, true); + if(category::flags::root == wd->other.category) + interface_type::enable_window(wd->root, enabled); } } bool window_enabled(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - return (restrict::wd_manager().available(iwd) ? iwd->flags.enabled : false); + return (is_window(wd) ? wd->flags.enabled : false); } //refresh_window //@brief: Refresh the window and display it immediately. void refresh_window(window wd) { - restrict::wd_manager().update(reinterpret_cast(wd), true, false); + restrict::wd_manager().update(wd, true, false); } void refresh_window_tree(window wd) { - restrict::wd_manager().refresh_tree(reinterpret_cast(wd)); + restrict::wd_manager().refresh_tree(wd); } //update_window //@brief: it displays a window immediately without refreshing. void update_window(window wd) { - restrict::wd_manager().update(reinterpret_cast(wd), false, true); + restrict::wd_manager().update(wd, false, true); } void window_caption(window wd, const std::string& title_utf8) { throw_not_utf8(title_utf8); - auto const iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) - iwd->widget_notifier->caption(to_nstring(title_utf8)); + if (is_window(wd)) + wd->widget_notifier->caption(to_nstring(title_utf8)); } void window_caption(window wd, const std::wstring& title) { - auto const iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) - iwd->widget_notifier->caption(to_nstring(title)); + if (is_window(wd)) + wd->widget_notifier->caption(to_nstring(title)); } std::string window_caption(window wd) { - auto const iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) - return to_utf8(iwd->widget_notifier->caption()); + if (is_window(wd)) + return to_utf8(wd->widget_notifier->caption()); return{}; } void window_cursor(window wd, cursor cur) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) + if(is_window(wd)) { - iwd->predef_cursor = cur; - restrict::bedrock.update_cursor(iwd); + wd->predef_cursor = cur; + restrict::bedrock.update_cursor(wd); } } cursor window_cursor(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) - return iwd->predef_cursor; + if(is_window(wd)) + return wd->predef_cursor; return cursor::arrow; } bool is_focus_ready(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) - return (iwd->root_widget->other.attribute.root->focus == iwd); + if(is_window(wd)) + return (wd->root_widget->other.attribute.root->focus == wd); return false; } void activate_window(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) + if (is_window(wd)) { - if(iwd->flags.take_active) - interface_type::activate_window(iwd->root); + if(wd->flags.take_active) + interface_type::activate_window(wd->root); } } window focus_window() { internal_scope_guard lock; - return reinterpret_cast(restrict::bedrock.focus()); + return restrict::bedrock.focus(); } void focus_window(window wd) { - restrict::wd_manager().set_focus(reinterpret_cast(wd), false, arg_focus::reason::general); - restrict::wd_manager().update(reinterpret_cast(wd), false, false); + restrict::wd_manager().set_focus(wd, false, arg_focus::reason::general); + restrict::wd_manager().update(wd, false, false); } window capture_window() { - return reinterpret_cast(restrict::wd_manager().capture_window()); + return restrict::wd_manager().capture_window(); } void set_capture(window wd, bool ignore_children) { - restrict::wd_manager().capture_window(reinterpret_cast(wd), true, ignore_children); + restrict::wd_manager().capture_window(wd, true, ignore_children); } void release_capture(window wd) { //The 3rd parameter is useless when the 2nd parameter is false. - restrict::wd_manager().capture_window(reinterpret_cast(wd), false, false); + restrict::wd_manager().capture_window(wd, false, false); } void modal_window(window wd) { - auto const iwd = reinterpret_cast(wd); - internal_scope_guard isg; + internal_scope_guard lock; - if (!restrict::wd_manager().available(iwd)) + if (empty_window(wd)) return; - if ((iwd->other.category == category::flags::root) && (iwd->flags.modal == false)) + if ((wd->other.category == category::flags::root) && (wd->flags.modal == false)) { - iwd->flags.modal = true; + wd->flags.modal = true; #if defined(NANA_X11) - interface_type::set_modal(iwd->root); + interface_type::set_modal(wd->root); #endif - restrict::wd_manager().show(iwd, true); + restrict::wd_manager().show(wd, true); } else return; @@ -1070,29 +1018,28 @@ namespace API void wait_for(window wd) { internal_scope_guard lock; - if (restrict::wd_manager().available(reinterpret_cast(wd))) + if (is_window(wd)) restrict::bedrock.pump_event(wd, false); } color fgcolor(window wd) { internal_scope_guard lock; - if (restrict::wd_manager().available(reinterpret_cast(wd))) - return reinterpret_cast(wd)->annex.scheme->foreground.get_color(); + if (is_window(wd)) + return wd->annex.scheme->foreground.get_color(); return{}; } color fgcolor(window wd, const color& clr) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) + if (is_window(wd)) { - auto prev = iwd->annex.scheme->foreground.get_color(); + auto prev = wd->annex.scheme->foreground.get_color(); if (prev != clr) { - iwd->annex.scheme->foreground = clr; - restrict::wd_manager().update(iwd, true, false); + wd->annex.scheme->foreground = clr; + refresh_window(wd); } return prev; } @@ -1102,27 +1049,26 @@ namespace API color bgcolor(window wd) { internal_scope_guard lock; - if (restrict::wd_manager().available(reinterpret_cast(wd))) - return reinterpret_cast(wd)->annex.scheme->background.get_color(); + if (is_window(wd)) + return wd->annex.scheme->background.get_color(); return{}; } color bgcolor(window wd, const color& clr) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) + if (is_window(wd)) { - auto prev = iwd->annex.scheme->background.get_color(); + auto prev = wd->annex.scheme->background.get_color(); if (prev != clr) { - iwd->annex.scheme->background = clr; + wd->annex.scheme->background = clr; //If the bground mode of this window is basic, it should remake the background - if (iwd->effect.bground && iwd->effect.bground_fade_rate < 0.01) // fade rate < 0.01 means it is basic mode - iwd->flags.make_bground_declared = true; + if (wd->effect.bground && wd->effect.bground_fade_rate < 0.01) // fade rate < 0.01 means it is basic mode + wd->flags.make_bground_declared = true; - restrict::wd_manager().update(iwd, true, false); + refresh_window(wd); } return prev; } @@ -1132,22 +1078,21 @@ namespace API color activated_color(window wd) { internal_scope_guard lock; - if (restrict::wd_manager().available(reinterpret_cast(wd))) - return reinterpret_cast(wd)->annex.scheme->activated.get_color(); + if (is_window(wd)) + return wd->annex.scheme->activated.get_color(); return{}; } color activated_color(window wd, const color& clr) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) + if (is_window(wd)) { - auto prev = iwd->annex.scheme->activated.get_color(); + auto prev = wd->annex.scheme->activated.get_color(); if (prev != clr) { - iwd->annex.scheme->activated = clr; - restrict::wd_manager().update(iwd, true, false); + wd->annex.scheme->activated = clr; + refresh_window(wd); } return prev; } @@ -1236,7 +1181,7 @@ namespace API private: caret_interface* _m_caret() const { - if (restrict::wd_manager().available(window_) && window_->annex.caret_ptr) + if (is_window(window_) && window_->annex.caret_ptr) return window_->annex.caret_ptr; if (throw_) @@ -1251,27 +1196,25 @@ namespace API void create_caret(window wd, const size& caret_size) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd) && !(iwd->annex.caret_ptr)) - iwd->annex.caret_ptr = new ::nana::detail::caret(iwd, caret_size); + if (is_window(wd) && !(wd->annex.caret_ptr)) + wd->annex.caret_ptr = new ::nana::detail::caret(wd, caret_size); } void destroy_caret(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) + if(is_window(wd)) { - auto p = iwd->annex.caret_ptr; - iwd->annex.caret_ptr = nullptr; + auto p = wd->annex.caret_ptr; + wd->annex.caret_ptr = nullptr; delete p; } } std::unique_ptr open_caret(window window_handle, bool disable_throw) { - auto p = new caret_proxy{ reinterpret_cast(window_handle) }; + auto p = new caret_proxy{ window_handle }; if (disable_throw) p->disable_throw(); @@ -1280,72 +1223,63 @@ namespace API void tabstop(window wd) { - restrict::wd_manager().enable_tabstop(reinterpret_cast(wd)); + restrict::wd_manager().enable_tabstop(wd); } //eat_tabstop //@brief: set a eating tab window that it processes a pressing of tab itself void eat_tabstop(window wd, bool eat) { - if(wd) + internal_scope_guard lock; + if(is_window(wd)) { - auto iwd = reinterpret_cast(wd); - internal_scope_guard isg; - if(restrict::wd_manager().available(iwd)) - { - if(eat) - iwd->flags.tab |= ::nana::detail::tab_type::eating; - else - iwd->flags.tab &= ~::nana::detail::tab_type::eating; - } + if(eat) + wd->flags.tab |= ::nana::detail::tab_type::eating; + else + wd->flags.tab &= ~::nana::detail::tab_type::eating; } } window move_tabstop(window wd, bool next) { - basic_window* ts_wd = restrict::wd_manager().tabstop(reinterpret_cast(wd), next); - restrict::wd_manager().set_focus(ts_wd, false, arg_focus::reason::general); - restrict::wd_manager().update(ts_wd, false, false); - return reinterpret_cast(ts_wd); + auto prev_wd = restrict::wd_manager().tabstop(wd, next); + restrict::wd_manager().set_focus(prev_wd, false, arg_focus::reason::general); + restrict::wd_manager().update(prev_wd, false, false); + + return prev_wd; } void take_active(window wd, bool active, window take_if_active_false) { - auto const iwd = reinterpret_cast(wd); - auto take_if_false = reinterpret_cast(take_if_active_false); - internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) + if (is_window(wd)) { - if (active || (take_if_false && (restrict::wd_manager().available(take_if_false) == false))) - take_if_false = 0; + if (active || (take_if_active_false && empty_window(take_if_active_false))) + take_if_active_false = nullptr; - iwd->flags.take_active = active; - iwd->other.active_window = take_if_false; + wd->flags.take_active = active; + wd->other.active_window = take_if_active_false; } } bool window_graphics(window wd, nana::paint::graphics& graph) { - auto iwd = reinterpret_cast(wd); - internal_scope_guard lock; - if (!restrict::wd_manager().available(iwd)) + if (empty_window(wd)) return false; - graph.make(iwd->drawer.graphics.size()); - graph.bitblt(0, 0, iwd->drawer.graphics); - nana::detail::window_layout::paste_children_to_graphics(iwd, graph); + graph.make(wd->drawer.graphics.size()); + graph.bitblt(0, 0, wd->drawer.graphics); + nana::detail::window_layout::paste_children_to_graphics(wd, graph); return true; } bool root_graphics(window wd, nana::paint::graphics& graph) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) + if(is_window(wd)) { - graph = *(iwd->root_graph); + graph = *(wd->root_graph); return true; } return false; @@ -1353,51 +1287,47 @@ namespace API bool get_visual_rectangle(window wd, nana::rectangle& r) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) - return nana::detail::window_layout::read_visual_rectangle(iwd, r); + if (is_window(wd)) + return nana::detail::window_layout::read_visual_rectangle(wd, r); return false; } void typeface(window wd, const nana::paint::font& font) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) + if(is_window(wd)) { - iwd->drawer.graphics.typeface(font); - iwd->drawer.typeface_changed(); - restrict::wd_manager().update(iwd, true, false); + wd->drawer.graphics.typeface(font); + wd->drawer.typeface_changed(); + refresh_window(wd); } } nana::paint::font typeface(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) - return iwd->drawer.graphics.typeface(); + if(is_window(wd)) + return wd->drawer.graphics.typeface(); return{}; } bool calc_screen_point(window wd, nana::point& pos) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) + if(is_window(wd)) { - pos += iwd->pos_root; - return interface_type::calc_screen_point(iwd->root, pos); + pos += wd->pos_root; + return interface_type::calc_screen_point(wd->root, pos); } return false; } bool calc_window_point(window wd, nana::point& pos) { - return restrict::wd_manager().calc_window_point(reinterpret_cast(wd), pos); + return restrict::wd_manager().calc_window_point(wd, pos); } window find_window(const nana::point& pos) @@ -1407,65 +1337,59 @@ namespace API { ::nana::point clipos{pos}; interface_type::calc_window_point(wd, clipos); - return reinterpret_cast( - restrict::wd_manager().find_window(wd, clipos, true)); + return restrict::wd_manager().find_window(wd, clipos, true); } return nullptr; } bool is_window_zoomed(window wd, bool ask_for_max) { - auto const iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) + if (is_window(wd)) { - if (iwd->other.category == nana::category::flags::root) - return interface_type::is_window_zoomed(iwd->root, ask_for_max); + if (wd->other.category == nana::category::flags::root) + return interface_type::is_window_zoomed(wd->root, ask_for_max); } return false; } void widget_borderless(window wd, bool enabled) { - auto const iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) + if (is_window(wd)) { - if ((category::flags::widget == iwd->other.category) && (iwd->flags.borderless != enabled)) + if ((category::flags::widget == wd->other.category) && (wd->flags.borderless != enabled)) { - iwd->flags.borderless = enabled; - restrict::wd_manager().update(iwd, true, false); + wd->flags.borderless = enabled; + refresh_window(wd); } } } bool widget_borderless(window wd) { - auto const iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) - return iwd->flags.borderless; + if (is_window(wd)) + return wd->flags.borderless; return false; } nana::mouse_action mouse_action(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) - return iwd->flags.action; + if(is_window(wd)) + return wd->flags.action; return nana::mouse_action::normal; } nana::element_state element_state(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if(restrict::wd_manager().available(iwd)) + if(is_window(wd)) { - const bool is_focused = (iwd->root_widget->other.attribute.root->focus == iwd); - switch(iwd->flags.action) + const bool is_focused = (wd->root_widget->other.attribute.root->focus == wd); + switch(wd->flags.action) { case nana::mouse_action::normal: case nana::mouse_action::normal_captured: @@ -1475,7 +1399,7 @@ namespace API case nana::mouse_action::pressed: return nana::element_state::pressed; default: - if(false == iwd->flags.enabled) + if(false == wd->flags.enabled) return nana::element_state::disabled; } } @@ -1484,12 +1408,11 @@ namespace API bool ignore_mouse_focus(window wd, bool ignore) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd)) + if (is_window(wd)) { - auto state = iwd->flags.ignore_mouse_focus; - iwd->flags.ignore_mouse_focus = ignore; + auto state = wd->flags.ignore_mouse_focus; + wd->flags.ignore_mouse_focus = ignore; return state; } return false; @@ -1497,24 +1420,22 @@ namespace API bool ignore_mouse_focus(window wd) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - return (restrict::wd_manager().available(iwd) ? iwd->flags.ignore_mouse_focus : false); + return (is_window(wd) ? wd->flags.ignore_mouse_focus : false); } void at_safe_place(window wd, std::function fn) { - restrict::wd_manager().set_safe_place(reinterpret_cast(wd), std::move(fn)); + restrict::wd_manager().set_safe_place(wd, std::move(fn)); } std::optional> content_extent(window wd, unsigned limited_px, bool limit_width) { - auto iwd = reinterpret_cast(wd); internal_scope_guard lock; - if (restrict::wd_manager().available(iwd) && iwd->annex.content_measurer) + if (is_window(wd) && wd->annex.content_measurer) { - paint::graphics* graph = &iwd->drawer.graphics; + paint::graphics* graph = &wd->drawer.graphics; paint::graphics temp_graph; if (graph->empty()) { @@ -1523,9 +1444,9 @@ namespace API graph = &temp_graph; } - auto extent = iwd->annex.content_measurer->measure(*graph, limited_px, limit_width); + auto extent = wd->annex.content_measurer->measure(*graph, limited_px, limit_width); if (extent) - return std::make_pair(extent.value(), extent.value() + iwd->annex.content_measurer->extension()); + return std::make_pair(extent.value(), extent.value() + wd->annex.content_measurer->extension()); } return{}; @@ -1538,11 +1459,9 @@ namespace API dragdrop_status window_dragdrop_status(::nana::window wd) { - auto real_wd = reinterpret_cast(wd); internal_scope_guard lock; - - if (restrict::wd_manager().available(real_wd)) - return real_wd->other.dnd_state; + if (is_window(wd)) + return wd->other.dnd_state; return dragdrop_status::not_ready; } diff --git a/source/gui/state_cursor.cpp b/source/gui/state_cursor.cpp index 5644ed83..817b6dec 100644 --- a/source/gui/state_cursor.cpp +++ b/source/gui/state_cursor.cpp @@ -9,18 +9,18 @@ * * @file: nana/gui/state_cursor.cpp */ + +#include "detail/basic_window.hpp" #include #include -#include #include namespace nana { - state_cursor::state_cursor(window handle, cursor cur) - : handle_(handle) + state_cursor::state_cursor(window wd, cursor cur) + : handle_(wd) { auto & brock = detail::bedrock::instance(); - auto wd = reinterpret_cast(handle); if (brock.wd_manager().available(wd)) brock.define_state_cursor(wd, cur, nullptr); else @@ -39,10 +39,9 @@ namespace nana { if (handle_) { + nana::internal_scope_guard lock; auto & brock = detail::bedrock::instance(); - auto wd = reinterpret_cast(handle_); - if (brock.wd_manager().available(wd)) - brock.undefine_state_cursor(wd, nullptr); + brock.undefine_state_cursor(handle_, nullptr); } handle_ = rhs.handle_; rhs.handle_ = nullptr; @@ -54,10 +53,9 @@ namespace nana { if (handle_) { + nana::internal_scope_guard lock; auto & brock = detail::bedrock::instance(); - auto wd = reinterpret_cast(handle_); - if (brock.wd_manager().available(wd)) - brock.undefine_state_cursor(wd, nullptr); + brock.undefine_state_cursor(handle_, nullptr); } } } \ No newline at end of file diff --git a/source/gui/wvl.cpp b/source/gui/wvl.cpp index 7497d3c4..e280aef8 100644 --- a/source/gui/wvl.cpp +++ b/source/gui/wvl.cpp @@ -29,7 +29,7 @@ namespace nana { void form_loader_private::insert_form(::nana::widget* p) { - bedrock::instance().manage_form_loader(reinterpret_cast(p->handle()), true); + bedrock::instance().manage_form_loader(p->handle(), true); } }