diff options
author | 杨宇千 <crupest@outlook.com> | 2018-11-10 22:39:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-10 22:39:26 +0800 |
commit | 8b04c0dd788be75c2dd7d8f58aebc7d6bf6752df (patch) | |
tree | 2d00b4f6a7af93a13d271d78e6ef682c335c91c7 /src/ui/window.cpp | |
parent | 7c2fb4578b6997b5ab0d98121cda253f734139c1 (diff) | |
parent | b2eced8d9719eb00796c2674fc2c23ab0c9bbdbf (diff) | |
download | cru-8b04c0dd788be75c2dd7d8f58aebc7d6bf6752df.tar.gz cru-8b04c0dd788be75c2dd7d8f58aebc7d6bf6752df.tar.bz2 cru-8b04c0dd788be75c2dd7d8f58aebc7d6bf6752df.zip |
Merge pull request #11 from crupest/listitem
Add ListItem.
Diffstat (limited to 'src/ui/window.cpp')
-rw-r--r-- | src/ui/window.cpp | 79 |
1 files changed, 68 insertions, 11 deletions
diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 2737b70b..f8e6d4f3 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -98,6 +98,15 @@ namespace cru::ui ); } + inline POINT DipToPi(const Point& dip_point) + { + POINT result; + result.x = graph::DipToPixelX(dip_point.x); + result.y = graph::DipToPixelY(dip_point.y); + return result; + } + + namespace { Cursor::Ptr GetCursorInherit(Control* control) @@ -275,6 +284,41 @@ namespace cru::ui } } + void Window::SetWindowPosition(const Point& position) + { + if (IsWindowValid()) { + SetWindowPos( + hwnd_, nullptr, + graph::DipToPixelX(position.x), + graph::DipToPixelY(position.y), + 0, 0, + SWP_NOZORDER | SWP_NOSIZE + ); + } + } + + Point Window::PointToScreen(const Point& point) + { + if (!IsWindowValid()) + return Point::Zero(); + + auto p = DipToPi(point); + if (::ClientToScreen(GetWindowHandle(), &p) == 0) + throw Win32Error(::GetLastError(), "Failed transform point from window to screen."); + return PiToDip(p); + } + + Point Window::PointFromScreen(const Point& point) + { + if (!IsWindowValid()) + return Point::Zero(); + + auto p = DipToPi(point); + if (::ScreenToClient(GetWindowHandle(), &p) == 0) + throw Win32Error(::GetLastError(), "Failed transform point from screen to window."); + return PiToDip(p); + } + bool Window::HandleWindowMessage(HWND hwnd, int msg, WPARAM w_param, LPARAM l_param, LRESULT & result) { if (!native_message_event.IsNoHandler()) @@ -429,10 +473,32 @@ namespace cru::ui } + void Window::WindowInvalidateLayout() + { + if (is_layout_invalid_) + return; + + is_layout_invalid_ = true; + InvokeLater([this] + { + if (is_layout_invalid_) + Relayout(); + }); + } + void Window::Relayout() { - OnMeasureCore(GetSize()); + Measure(GetSize()); OnLayoutCore(Rect(Point::Zero(), GetSize())); + is_layout_invalid_ = false; + } + + void Window::SetSizeFitContent(const Size& max_size) + { + Measure(max_size); + SetClientSize(GetDesiredSize()); + OnLayoutCore(Rect(Point::Zero(), GetSize())); + is_layout_invalid_ = false; } void Window::RefreshControlList() { @@ -557,15 +623,6 @@ namespace cru::ui } } - Size Window::OnMeasureContent(const Size& available_size) - { - for (auto control: GetChildren()) - { - control->Measure(available_size); - } - return available_size; - } - void Window::OnDestroyInternal() { WindowManager::GetInstance()->UnregisterWindow(hwnd_); hwnd_ = nullptr; @@ -597,7 +654,7 @@ namespace cru::ui void Window::OnResizeInternal(const int new_width, const int new_height) { render_target_->ResizeBuffer(new_width, new_height); if (!(new_width == 0 && new_height == 0)) - InvalidateLayout(); + WindowInvalidateLayout(); } void Window::OnSetFocusInternal() |