fix an issue of child root window(nested_form)

This commit is contained in:
Jinhao 2015-12-22 00:41:58 +08:00
parent 75800b2e78
commit 9bb0e8eb34
3 changed files with 109 additions and 28 deletions

View File

@ -70,7 +70,8 @@ namespace detail
static void capture_window(native_window_type, bool);
static nana::point cursor_position();
static native_window_type get_owner_window(native_window_type);
static native_window_type set_parent(native_window_type child, native_window_type new_parent);
static native_window_type parent_window(native_window_type);
static native_window_type parent_window(native_window_type child, native_window_type new_parent, bool returns_previous);
//For Caret
static void caret_create(native_window_type, const ::nana::size&);
static void caret_destroy(native_window_type);

View File

@ -281,7 +281,8 @@ namespace nana{
attr_mask, &win_attr);
if(handle)
{
if(owner)
//make owner if it is a popup window
if((!nested) && owner)
restrict::spec.make_owner(owner, reinterpret_cast<native_window_type>(handle));
XTextProperty name;
@ -417,8 +418,6 @@ namespace nana{
if(handle)
{
restrict::spec.make_owner(parent, reinterpret_cast<native_window_type>(handle));
XTextProperty name;
char text[] = "Nana Child Window";
char * str = text;
@ -786,21 +785,30 @@ namespace nana{
#if defined(NANA_WINDOWS)
::RECT r;
::GetWindowRect(reinterpret_cast<HWND>(wd), & r);
HWND owner = ::GetWindow(reinterpret_cast<HWND>(wd), GW_OWNER);
if(owner)
HWND coord_wd = ::GetWindow(reinterpret_cast<HWND>(wd), GW_OWNER);
if (!coord_wd)
coord_wd = ::GetParent(reinterpret_cast<HWND>(wd));
if (coord_wd)
{
::POINT pos = {r.left, r.top};
::ScreenToClient(owner, &pos);
::ScreenToClient(coord_wd, &pos);
return nana::point(pos.x, pos.y);
}
return nana::point(r.left, r.top);
#elif defined(NANA_X11)
int x, y;
nana::detail::platform_scope_guard psg;
Window root = reinterpret_cast<Window>(restrict::spec.get_owner(wd));
if(root == 0) root = restrict::spec.root_window();
Window coord_wd = reinterpret_cast<Window>(restrict::spec.get_owner(wd));
if(!coord_wd)
{
coord_wd = reinterpret_cast<Window>(parent_window(wd));
if(!coord_wd)
coord_wd = restrict::spec.root_window();
}
Window child;
if(True == ::XTranslateCoordinates(restrict::spec.open_display(), reinterpret_cast<Window>(wd), root, 0, 0, &x, &y, &child))
if(True == ::XTranslateCoordinates(restrict::spec.open_display(), reinterpret_cast<Window>(wd), coord_wd, 0, 0, &x, &y, &child))
return nana::point(x, y);
return nana::point(0, 0);
#endif
@ -1202,14 +1210,50 @@ namespace nana{
#endif
}
native_window_type native_interface::set_parent(native_window_type child, native_window_type new_parent)
native_window_type native_interface::parent_window(native_window_type wd)
{
#ifdef NANA_WINDOWS
return reinterpret_cast<native_window_type>(
return reinterpret_cast<native_window_type>(::GetParent(reinterpret_cast<HWND>(wd)));
#elif defined(NANA_X11)
Window root;
Window parent;
Window * children;
unsigned size;
platform_scope_guard lock;
if(0 != ::XQueryTree(restrict::spec.open_display(), reinterpret_cast<Window>(wd),
&root, &parent, &children, &size))
{
::XFree(children);
return reinterpret_cast<native_window_type>(parent);
}
return nullptr;
#endif
}
native_window_type native_interface::parent_window(native_window_type child, native_window_type new_parent, bool returns_previous)
{
#ifdef NANA_WINDOWS
auto prev = reinterpret_cast<native_window_type>(
::SetParent(reinterpret_cast<HWND>(child), reinterpret_cast<HWND>(new_parent))
);
#elif defined(NANA_X11)
::SetWindowPos(reinterpret_cast<HWND>(child), NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED);
return (returns_previous ? prev : nullptr);
#elif defined(NANA_X11)
native_window_type prev = nullptr;
platform_scope_guard lock;
if(returns_previous)
prev = parent_window(child);
::XReparentWindow(restrict::spec.open_display(),
reinterpret_cast<Window>(child), reinterpret_cast<Window>(new_parent),
0, 0);
return prev;
#endif
}

View File

@ -550,7 +550,7 @@ namespace detail
std::lock_guard<decltype(mutex_)> lock(mutex_);
if (impl_->wd_register.available(wd))
{
if(wd->other.category != category::root_tag::value)
if (category::flags::root != wd->other.category)
{
//Move child widgets
if (x != wd->pos_owner.x || y != wd->pos_owner.y)
@ -570,9 +570,21 @@ namespace detail
return true;
}
}
else if(false == passive)
else if (!passive)
{
//Check if this root is a nested
if (wd->parent && (category::flags::root != wd->parent->other.category))
{
//The parent of the window is not a root, the position should
//be transformed to a position based on its parent.
x += wd->parent->pos_root.x;
y += wd->parent->pos_root.y;
}
native_interface::move_window(wd->root, x, y);
}
}
return false;
}
@ -610,22 +622,36 @@ namespace detail
}
else
{
::nana::rectangle root_r = r;
//Move event should not get called here,
//because the window is a root, the event will get called by system event handler.
//Check if this root is a nested
if (wd->parent && (category::flags::root != wd->parent->other.category))
{
//The parent of the window is not a root, the position should
//be transformed to a position based on its parent.
root_r.x += wd->parent->pos_root.x;
root_r.y += wd->parent->pos_root.y;
}
if(size_changed)
{
wd->dimension.width = r.width;
wd->dimension.height = r.height;
wd->dimension.width = root_r.width;
wd->dimension.height = root_r.height;
wd->drawer.graphics.make(wd->dimension);
wd->root_graph->make(wd->dimension);
native_interface::move_window(wd->root, r);
native_interface::move_window(wd->root, root_r);
arg_resized arg;
arg.window_handle = reinterpret_cast<window>(wd);
arg.width = r.width;
arg.height = r.height;
arg.width = root_r.width;
arg.height = root_r.height;
brock.emit(event_code::resized, wd, arg, true, brock.get_thread_context());
}
else
native_interface::move_window(wd->root, r.x, r.y);
native_interface::move_window(wd->root, root_r.x, root_r.y);
}
return (moved || size_changed);
@ -1456,12 +1482,15 @@ namespace detail
std::function<void(core_window_t*, const nana::point&)> set_pos_root;
set_pos_root = [&set_pos_root](core_window_t* wd, const nana::point& delta_pos)
{
wd->pos_root -= delta_pos;
for (auto child : wd->children)
{
if (category::flags::root == child->other.category)
{
native_interface::set_parent(child->root, wd->root);
auto pos = native_interface::window_position(child->root);
native_interface::parent_window(child->root, wd->root, false);
pos -= delta_pos;
native_interface::move_window(child->root, pos.x, pos.y);
}
else
{
@ -1471,6 +1500,8 @@ namespace detail
set_pos_root(child, delta_pos);
}
}
wd->pos_root -= delta_pos;
};
set_pos_root(wd, delta_pos);
@ -1550,7 +1581,7 @@ namespace detail
void window_manager::_m_move_core(core_window_t* wd, const point& delta)
{
if(wd->other.category != category::root_tag::value) //A root widget always starts at (0, 0) and its childs are not to be changed
if(category::flags::root != wd->other.category) //A root widget always starts at (0, 0) and its childs are not to be changed
{
wd->pos_root += delta;
if (category::flags::frame != wd->other.category)
@ -1567,6 +1598,11 @@ namespace detail
for (auto child : wd->children)
_m_move_core(child, delta);
}
else
{
auto pos = native_interface::window_position(wd->root) + delta;
native_interface::move_window(wd->root, pos.x, pos.y);
}
}
//_m_find