11#include " flutter/shell/platform/windows/win32_flutter_window.h"
22
33#include < chrono>
4+ #include < map>
45
56namespace flutter {
67
8+ namespace {
9+
710// The Windows DPI system is based on this
811// constant for machines running at 100% scaling.
912constexpr int base_dpi = 96 ;
@@ -12,9 +15,33 @@ constexpr int base_dpi = 96;
1215// arbitrarily to get something that feels reasonable.
1316constexpr int kScrollOffsetMultiplier = 20 ;
1417
18+ // Maps a Flutter cursor name to an HCURSOR.
19+ //
20+ // Returns the arrow cursor for unknown constants.
21+ static HCURSOR GetCursorByName (const std::string& cursor_name) {
22+ static auto * cursors = new std::map<std::string, const wchar_t *>{
23+ {" none" , nullptr },
24+ {" basic" , IDC_ARROW},
25+ {" click" , IDC_HAND},
26+ {" text" , IDC_IBEAM},
27+ {" forbidden" , IDC_NO},
28+ {" horizontalDoubleArrow" , IDC_SIZEWE},
29+ {" verticalDoubleArrow" , IDC_SIZENS},
30+ };
31+ const wchar_t * idc_name = IDC_ARROW;
32+ auto it = cursors->find (cursor_name);
33+ if (it != cursors->end ()) {
34+ idc_name = it->second ;
35+ }
36+ return ::LoadCursor (nullptr , idc_name);
37+ }
38+
39+ } // namespace
40+
1541Win32FlutterWindow::Win32FlutterWindow (int width, int height)
1642 : binding_handler_delegate_(nullptr ) {
1743 Win32Window::InitializeChild (" FLUTTERVIEW" , width, height);
44+ current_cursor_ = ::LoadCursor (nullptr , IDC_ARROW);
1845}
1946
2047Win32FlutterWindow::~Win32FlutterWindow () {}
@@ -35,6 +62,10 @@ PhysicalWindowBounds Win32FlutterWindow::GetPhysicalWindowBounds() {
3562 return {GetCurrentWidth (), GetCurrentHeight ()};
3663}
3764
65+ void Win32FlutterWindow::UpdateFlutterCursor (const std::string& cursor_name) {
66+ current_cursor_ = GetCursorByName (cursor_name);
67+ }
68+
3869// Translates button codes from Win32 API to FlutterPointerMouseButtons.
3970static uint64_t ConvertWinButtonToFlutterButton (UINT button) {
4071 switch (button) {
@@ -90,6 +121,10 @@ void Win32FlutterWindow::OnPointerLeave() {
90121 binding_handler_delegate_->OnPointerLeave ();
91122}
92123
124+ void Win32FlutterWindow::OnSetCursor () {
125+ ::SetCursor (current_cursor_);
126+ }
127+
93128void Win32FlutterWindow::OnText (const std::u16string& text) {
94129 binding_handler_delegate_->OnText (text);
95130}
0 commit comments