From 58b206cb931a3376e3e6fb84c453a237cf765c57 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Tue, 24 Mar 2015 12:12:36 +0800 Subject: [PATCH] add new outline size API::window_outline_size changes the window size(not client area size) for a native window --- include/nana/gui/programming_interface.hpp | 8 ++-- include/nana/gui/widgets/widget.hpp | 10 ++++ source/gui/detail/native_window_interface.cpp | 29 ++++-------- source/gui/programming_interface.cpp | 46 +++++++++++++++++-- 4 files changed, 67 insertions(+), 26 deletions(-) diff --git a/include/nana/gui/programming_interface.hpp b/include/nana/gui/programming_interface.hpp index b65a15fc..7caf038b 100644 --- a/include/nana/gui/programming_interface.hpp +++ b/include/nana/gui/programming_interface.hpp @@ -193,7 +193,7 @@ namespace API return *comp_wdg_colors; } - nana::point window_position(window); + point window_position(window); void move_window(window, int x, int y); void move_window(window wd, const rectangle&); @@ -203,9 +203,11 @@ namespace API void draw_through(window, std::function); void map_through_widgets(window, native_drawable_type); - nana::size window_size(window); + size window_size(window); void window_size(window, const size&); - bool window_rectangle(window, rectangle&); + size window_outline_size(window); + void window_outline_size(window, const size&); + bool get_window_rectangle(window, rectangle&); bool track_window_size(window, const size&, bool true_for_max); ///< Sets the minimum or maximum tracking size of a window. void window_enabled(window, bool); bool window_enabled(window); diff --git a/include/nana/gui/widgets/widget.hpp b/include/nana/gui/widgets/widget.hpp index 2a010b55..9d298fbe 100644 --- a/include/nana/gui/widgets/widget.hpp +++ b/include/nana/gui/widgets/widget.hpp @@ -409,6 +409,16 @@ namespace nana { API::map_through_widgets(handle(), drawable); } + + void outline_size(const ::nana::size& sz) + { + API::window_outline_size(handle(), sz); + } + + ::nana::size outline_size() const + { + return API::window_outline_size(handle()); + } protected: DrawerTrigger& get_drawer_trigger() { diff --git a/source/gui/detail/native_window_interface.cpp b/source/gui/detail/native_window_interface.cpp index 5f67669f..0ad45b61 100644 --- a/source/gui/detail/native_window_interface.cpp +++ b/source/gui/detail/native_window_interface.cpp @@ -213,30 +213,19 @@ namespace nana{ ::RECT wd_area; ::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)) + //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) { - ::MoveWindow(native_wd, r.x, r.y, r.width, r.height, true); + wd_area.left = pt.x; + wd_area.top = pt.y; } - 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; + 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); - } + ::MoveWindow(native_wd, wd_area.left, wd_area.top, wd_area.right + delta_w, wd_area.bottom + delta_h, true); ::GetClientRect(native_wd, &client); ::GetWindowRect(native_wd, &wd_area); diff --git a/source/gui/programming_interface.cpp b/source/gui/programming_interface.cpp index 9ba95f03..6af6945d 100644 --- a/source/gui/programming_interface.cpp +++ b/source/gui/programming_interface.cpp @@ -1,13 +1,14 @@ /* * Nana GUI Programming Interface Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2015 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/programming_interface.cpp + * @author: Jinhao */ #include @@ -598,7 +599,7 @@ namespace API nana::size window_size(window wd) { nana::rectangle r; - API::window_rectangle(wd, r); + API::get_window_rectangle(wd, r); return{ r.width, r.height }; } @@ -618,7 +619,46 @@ namespace API } } - bool window_rectangle(window wd, rectangle& r) + ::nana::size window_outline_size(window wd) + { + auto iwd = reinterpret_cast(wd); + internal_scope_guard lock; + if (!restrict::window_manager.available(iwd)) + return{}; + + auto sz = window_size(wd); + sz.width += iwd->extra_width; + sz.height += iwd->extra_height; + return sz; + } + + void window_outline_size(window wd, const size& sz) + { + auto iwd = reinterpret_cast(wd); + internal_scope_guard lock; + if (restrict::window_manager.available(iwd)) + { + if (category::flags::root == iwd->other.category) + { + size inner_size = sz; + if (inner_size.width < iwd->extra_width) + inner_size.width = 0; + else + inner_size.width -= iwd->extra_width; + + if (inner_size.height < iwd->extra_height) + inner_size.height = 0; + else + inner_size.height -= iwd->extra_height; + + window_size(wd, inner_size); + } + else + window_size(wd, sz); + } + } + + bool get_window_rectangle(window wd, rectangle& r) { auto iwd = reinterpret_cast(wd); internal_scope_guard lock;