@@ -14,6 +14,11 @@ static constexpr char kActivateSystemCursorMethod[] = "activateSystemCursor";
14
14
static constexpr char kSetSystemCursorMethod [] = " setSystemCursor" ;
15
15
16
16
static constexpr char kKindKey [] = " kind" ;
17
+ static constexpr char kCustomCursorBufferKey [] = " buffer" ;
18
+ static constexpr char kCustomCursorHotxKey [] = " hotx" ;
19
+ static constexpr char kCustomCursorHotyKey [] = " hoty" ;
20
+ static constexpr char kCustomCursorWidthKey [] = " width" ;
21
+ static constexpr char kCustomCursorHeightKey [] = " height" ;
17
22
18
23
namespace flutter {
19
24
@@ -47,18 +52,48 @@ void CursorHandler::HandleMethodCall(
47
52
delegate_->UpdateFlutterCursor (kind);
48
53
result->Success ();
49
54
} else if (method.compare (kSetSystemCursorMethod ) == 0 ) {
50
- const auto & map = std::get<EncodableMap>(*method_call.arguments ());
55
+ const auto & arguments = std::get<EncodableMap>(*method_call.arguments ());
56
+ auto buffer_iter = arguments.find (EncodableValue (std::string (kCustomCursorBufferKey )));
57
+ if (buffer_iter == arguments.end ()) {
58
+ result->Error (" Argument error" ,
59
+ " Missing argument buffer while trying to customize system cursor" );
60
+ return ;
61
+ }
51
62
auto buffer = std::get<std::vector<uint8_t >>(
52
- map.at (flutter::EncodableValue (" buffer" )));
53
- auto width = std::get<int >(map.at (flutter::EncodableValue (" width" )));
54
- auto height = std::get<int >(map.at (flutter::EncodableValue (" height" )));
55
- auto hotx = std::get<double >(map.at (flutter::EncodableValue (" hotx" )));
56
- auto hoty = std::get<double >(map.at (flutter::EncodableValue (" hoty" )));
63
+ arguments.at (flutter::EncodableValue (" buffer" )));
64
+ auto width_iter = arguments.find (EncodableValue (std::string (kCustomCursorWidthKey )));
65
+ if (width_iter == arguments.end ()) {
66
+ result->Error (" Argument error" ,
67
+ " Missing argument width while trying to customize system cursor" );
68
+ return ;
69
+ }
70
+ auto width = std::get<int >(arguments.at (flutter::EncodableValue (" width" )));
71
+ auto height_iter = arguments.find (EncodableValue (std::string (kCustomCursorHeightKey )));
72
+ if (height_iter == arguments.end ()) {
73
+ result->Error (" Argument error" ,
74
+ " Missing argument height while trying to customize system cursor" );
75
+ return ;
76
+ }
77
+ auto height = std::get<int >(arguments.at (flutter::EncodableValue (" height" )));
78
+ auto hotx_iter = arguments.find (EncodableValue (std::string (kCustomCursorHotxKey )));
79
+ if (hotx_iter == arguments.end ()) {
80
+ result->Error (" Argument error" ,
81
+ " Missing argument hotx while trying to customize system cursor" );
82
+ return ;
83
+ }
84
+ auto hotx = std::get<double >(arguments.at (flutter::EncodableValue (" hotx" )));
85
+ auto hoty_iter = arguments.find (EncodableValue (std::string (kCustomCursorHotyKey )));
86
+ if (hoty_iter == arguments.end ()) {
87
+ result->Error (" Argument error" ,
88
+ " Missing argument hoty while trying to customize system cursor" );
89
+ return ;
90
+ }
91
+ auto hoty = std::get<double >(arguments.at (flutter::EncodableValue (" hoty" )));
57
92
HCURSOR cursor = nullptr ;
58
93
// Flutter returns rawRgba, which has 8bits*4channels
59
94
auto bitmap = CreateBitmap (width, height, 1 , 32 , &buffer[0 ]);
60
95
if (bitmap == nullptr ) {
61
- result->Error (" Argument error" , " Invalid rawRgba bitmap from flutter " );
96
+ result->Error (" Argument error" , " Argument buffer must contain valid rawRgba bitmap " );
62
97
return ;
63
98
}
64
99
ICONINFO icon_info;
@@ -69,6 +104,10 @@ void CursorHandler::HandleMethodCall(
69
104
icon_info.hbmColor = bitmap;
70
105
cursor = CreateIconIndirect (&icon_info);
71
106
DeleteObject (bitmap);
107
+ if (cursor == nullptr ) {
108
+ result->Error (" Argument error" , " Create Icon failed, argument buffer must contain valid rawRgba bitmap" );
109
+ return ;
110
+ }
72
111
delegate_->SetFlutterCursor (cursor);
73
112
result->Success ();
74
113
} else {
0 commit comments