| 1241 | } |
| 1242 | |
| 1243 | void UpdateWidgetSelectedIndex(WindowBase* w, WidgetIndex widgetIndex, int32_t selectedIndex) |
| 1244 | { |
| 1245 | if (w->classification == WindowClass::custom) |
| 1246 | { |
| 1247 | auto& customInfo = GetInfo(static_cast<CustomWindow*>(w)); |
| 1248 | auto customWidgetInfo = customInfo.GetCustomWidgetDesc(w, widgetIndex); |
| 1249 | if (customWidgetInfo != nullptr) |
| 1250 | { |
| 1251 | auto& widget = w->widgets[widgetIndex]; |
| 1252 | |
| 1253 | auto lastSelectedIndex = customWidgetInfo->SelectedIndex; |
| 1254 | if (customWidgetInfo->Items.empty()) |
| 1255 | { |
| 1256 | selectedIndex = -1; |
| 1257 | } |
| 1258 | else |
| 1259 | { |
| 1260 | if (selectedIndex < 0 || static_cast<size_t>(selectedIndex) >= customWidgetInfo->Items.size()) |
| 1261 | { |
| 1262 | selectedIndex = 0; |
| 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | if (selectedIndex == -1) |
| 1267 | { |
| 1268 | widget.string = const_cast<utf8*>(""); |
| 1269 | } |
| 1270 | else |
| 1271 | { |
| 1272 | widget.string = const_cast<utf8*>(customWidgetInfo->Items[selectedIndex].c_str()); |
| 1273 | } |
| 1274 | customWidgetInfo->SelectedIndex = selectedIndex; |
| 1275 | |
| 1276 | auto* windowMgr = GetWindowManager(); |
| 1277 | windowMgr->InvalidateWidget(*w, widgetIndex); |
| 1278 | |
| 1279 | if (lastSelectedIndex != selectedIndex) |
| 1280 | { |
| 1281 | std::vector<JSValue> args; |
| 1282 | args.push_back(JS_NewInt32(customWidgetInfo->OnChange.context, selectedIndex)); |
| 1283 | InvokeEventHandler(customInfo.Owner, customWidgetInfo->OnChange, args); |
| 1284 | } |
| 1285 | } |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | std::vector<std::string> GetWidgetItems(WindowBase* w, WidgetIndex widgetIndex) |
| 1290 | { |
no test coverage detected