diff options
author | 杨宇千 <crupest@outlook.com> | 2018-11-27 21:12:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-27 21:12:10 +0800 |
commit | ee22597122612cd75fe62f5d808cb51478373fad (patch) | |
tree | 19b39da16f155451d5817e82e045d69d7410acbe /src/ui/window.cpp | |
parent | 30333294fcd5917a9f3572f0c4c6dfc2ec429a3c (diff) | |
parent | 5b770e3bf0f3f9e22454d9e092630b22f5916ebe (diff) | |
download | cru-ee22597122612cd75fe62f5d808cb51478373fad.tar.gz cru-ee22597122612cd75fe62f5d808cb51478373fad.tar.bz2 cru-ee22597122612cd75fe62f5d808cb51478373fad.zip |
Merge pull request #26 from crupest/3-scrollview
Develop scrollview.
Diffstat (limited to 'src/ui/window.cpp')
-rw-r--r-- | src/ui/window.cpp | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 87656cdc..9352b747 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -132,7 +132,8 @@ namespace cru::ui return new Window(tag_popup_constructor{}, parent, caption); } - Window::Window(tag_overlapped_constructor) : Control(WindowConstructorTag{}, this), control_list_({ this }) { + Window::Window(tag_overlapped_constructor) : Control(WindowConstructorTag{}, this) + { const auto window_manager = WindowManager::GetInstance(); hwnd_ = CreateWindowEx(0, @@ -148,7 +149,7 @@ namespace cru::ui AfterCreateHwnd(window_manager); } - Window::Window(tag_popup_constructor, Window* parent, const bool caption) : Control(WindowConstructorTag{}, this), control_list_({ this }) + Window::Window(tag_popup_constructor, Window* parent, const bool caption) : Control(WindowConstructorTag{}, this) { if (parent != nullptr && !parent->IsWindowValid()) throw std::runtime_error("Parent window is not valid."); @@ -411,6 +412,14 @@ namespace cru::ui result = 0; return true; } + case WM_MOUSEWHEEL: + POINT point; + point.x = GET_X_LPARAM(l_param); + point.y = GET_Y_LPARAM(l_param); + ScreenToClient(hwnd, &point); + OnMouseWheelInternal(GET_WHEEL_DELTA_WPARAM(w_param), point); + result = 0; + return true; case WM_KEYDOWN: OnKeyDownInternal(static_cast<int>(w_param)); result = 0; @@ -506,24 +515,6 @@ namespace cru::ui is_layout_invalid_ = false; } - void Window::RefreshControlList() { - control_list_.clear(); - TraverseDescendants([this](Control* control) { - this->control_list_.push_back(control); - }); - } - - Control * Window::HitTest(const Point & point) - { - for (auto i = control_list_.crbegin(); i != control_list_.crend(); ++i) { - auto control = *i; - if (control->IsPointInside(control->WindowToControl(point))) { - return control; - } - } - return nullptr; - } - bool Window::RequestFocusFor(Control * control) { if (control == nullptr) @@ -739,6 +730,20 @@ namespace cru::ui DispatchEvent(control, &Control::RaiseMouseUpEvent, nullptr, dip_point, button); } + void Window::OnMouseWheelInternal(short delta, POINT point) + { + const auto dip_point = PiToDip(point); + + Control* control; + + if (mouse_capture_control_) + control = mouse_capture_control_; + else + control = HitTest(dip_point); + + DispatchEvent(control, &Control::RaiseMouseWheelEvent, nullptr, dip_point, static_cast<float>(delta)); + } + void Window::OnKeyDownInternal(int virtual_code) { DispatchEvent(focus_control_, &Control::RaiseKeyDownEvent, nullptr, virtual_code); |