diff --git a/source/gui/detail/native_window_interface.cpp b/source/gui/detail/native_window_interface.cpp index a862af75..5f67669f 100644 --- a/source/gui/detail/native_window_interface.cpp +++ b/source/gui/detail/native_window_interface.cpp @@ -13,6 +13,7 @@ #include #include PLATFORM_SPEC_HPP #include +#include #if defined(NANA_WINDOWS) #if defined(NANA_MINGW) && defined(STD_THREAD_NOT_SUPPORTED) #include @@ -35,10 +36,10 @@ namespace nana{ #if defined(NANA_WINDOWS) static HICON icon(const nana::paint::image& img) { - paint::detail::image_ico * ico = dynamic_cast(img.image_ptr_.get()); + auto ico = dynamic_cast(img.image_ptr_.get()); if(ico && ico->ptr()) return *(ico->ptr()); - return 0; + return nullptr; } #endif }; @@ -51,17 +52,13 @@ namespace nana{ { struct window_extra_t { - HICON ico; - - window_extra_t() - : ico(0) - {} + HICON ico{nullptr}; }; typedef std::map map_t; private: - tray_manager(){} + tray_manager() = default; public: typedef window_extra_t extra_t; @@ -205,35 +202,49 @@ namespace nana{ if(owner && (nested == false)) ::ClientToScreen(reinterpret_cast(owner), &pt); - HWND wnd = ::CreateWindowEx(style_ex, STR("NanaWindowInternal"), STR("Nana Window"), + HWND native_wd = ::CreateWindowEx(style_ex, STR("NanaWindowInternal"), STR("Nana Window"), style, pt.x, pt.y, 100, 100, reinterpret_cast(owner), 0, ::GetModuleHandle(0), 0); //A window may have a border, this should be adjusted the client area fit for the specified size. ::RECT client; - ::GetClientRect(wnd, &client); //The right and bottom of client by GetClientRect indicate the width and height of the area + ::GetClientRect(native_wd, &client); //The right and bottom of client by GetClientRect indicate the width and height of the area ::RECT wd_area; - ::GetWindowRect(wnd, &wd_area); - wd_area.right -= wd_area.left; - wd_area.bottom -= wd_area.top; - if(nested) + ::GetWindowRect(native_wd, &wd_area); + + screen scr; + auto & disp = scr.from_point({wd_area.left, wd_area.right}); + + if ((disp.area().width == r.width && disp.area().height == r.height) || + (disp.workarea().width == r.width && disp.workarea().height == r.height)) { - wd_area.left = pt.x; - wd_area.top = pt.y; + ::MoveWindow(native_wd, r.x, r.y, r.width, r.height, true); + } + else + { + //a dimension with borders and caption title + wd_area.right -= wd_area.left; //wd_area.right = width + wd_area.bottom -= wd_area.top; //wd_area.bottom = height + if (nested) + { + wd_area.left = pt.x; + wd_area.top = pt.y; + } + + int delta_w = static_cast(r.width) - client.right; + int delta_h = static_cast(r.height) - client.bottom; + + ::MoveWindow(native_wd, wd_area.left, wd_area.top, wd_area.right + delta_w, wd_area.bottom + delta_h, true); } - int delta_w = static_cast(r.width) - client.right; - int delta_h = static_cast(r.height) - client.bottom; + ::GetClientRect(native_wd, &client); + ::GetWindowRect(native_wd, &wd_area); - ::MoveWindow(wnd, wd_area.left, wd_area.top, wd_area.right + delta_w, wd_area.bottom + delta_h, true); - - ::GetClientRect(wnd, &client); - ::GetWindowRect(wnd, &wd_area); wd_area.right -= wd_area.left; wd_area.bottom -= wd_area.top; - window_result result = {reinterpret_cast(wnd), + window_result result = { reinterpret_cast(native_wd), static_cast(client.right), static_cast(client.bottom), static_cast(wd_area.right - client.right), static_cast(wd_area.bottom - client.bottom)}; #elif defined(NANA_X11) diff --git a/source/gui/screen.cpp b/source/gui/screen.cpp index 952a17db..b16eb9d8 100644 --- a/source/gui/screen.cpp +++ b/source/gui/screen.cpp @@ -113,6 +113,7 @@ namespace nana #else void load_monitors() { + displays.clear(); displays.emplace_back(0, primary_monitor_size()); } #endif @@ -125,10 +126,12 @@ namespace nana impl_->load_monitors(); } - void screen::reload() { - impl_.reset(std::make_shared()); + //It is only when the screen is a moved-from object that impl_ is empty + if (!impl_) + impl_.swap(std::make_shared()); + impl_->load_monitors(); }