aboutsummaryrefslogtreecommitdiff
path: root/src/ui/window.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-11-10 22:28:40 +0800
committercrupest <crupest@outlook.com>2018-11-10 22:28:40 +0800
commitb2eced8d9719eb00796c2674fc2c23ab0c9bbdbf (patch)
tree2d00b4f6a7af93a13d271d78e6ef682c335c91c7 /src/ui/window.cpp
parent9cf812f77a879d5394a9158ce290f9d7e858de7d (diff)
downloadcru-b2eced8d9719eb00796c2674fc2c23ab0c9bbdbf.tar.gz
cru-b2eced8d9719eb00796c2674fc2c23ab0c9bbdbf.tar.bz2
cru-b2eced8d9719eb00796c2674fc2c23ab0c9bbdbf.zip
...
Diffstat (limited to 'src/ui/window.cpp')
-rw-r--r--src/ui/window.cpp57
1 files changed, 46 insertions, 11 deletions
diff --git a/src/ui/window.cpp b/src/ui/window.cpp
index 41104924..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())
@@ -444,14 +488,14 @@ namespace cru::ui
void Window::Relayout()
{
- OnMeasureCore(GetSize());
+ Measure(GetSize());
OnLayoutCore(Rect(Point::Zero(), GetSize()));
is_layout_invalid_ = false;
}
void Window::SetSizeFitContent(const Size& max_size)
{
- OnMeasureCore(max_size);
+ Measure(max_size);
SetClientSize(GetDesiredSize());
OnLayoutCore(Rect(Point::Zero(), GetSize()));
is_layout_invalid_ = false;
@@ -579,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;