| 373 | } |
| 374 | |
| 375 | void PickerWindow::OnClick(Point pt, WidgetID widget, int) |
| 376 | { |
| 377 | switch (widget) { |
| 378 | /* Class Picker */ |
| 379 | case WID_PW_CLASS_LIST: { |
| 380 | const auto vscroll = this->GetWidget<NWidgetScrollbar>(WID_PW_CLASS_SCROLL); |
| 381 | auto it = vscroll->GetScrolledItemFromWidget(this->classes, pt.y, this, WID_PW_CLASS_LIST); |
| 382 | if (it == this->classes.end()) return; |
| 383 | |
| 384 | if (this->callbacks.GetSelectedClass() != *it || HasBit(this->callbacks.mode, PFM_ALL)) { |
| 385 | ClrBit(this->callbacks.mode, PFM_ALL); // Disable showing all. |
| 386 | this->callbacks.SetSelectedClass(*it); |
| 387 | this->InvalidateData({PickerInvalidation::Type, PickerInvalidation::Position, PickerInvalidation::Validate}); |
| 388 | } |
| 389 | SndClickBeep(); |
| 390 | CloseWindowById(WC_SELECT_STATION, 0); |
| 391 | break; |
| 392 | } |
| 393 | |
| 394 | case WID_PW_MODE_ALL: |
| 395 | case WID_PW_MODE_USED: |
| 396 | case WID_PW_MODE_SAVED: |
| 397 | ToggleBit(this->callbacks.mode, widget - WID_PW_MODE_ALL); |
| 398 | if (!this->IsWidgetDisabled(WID_PW_MODE_ALL) && HasBit(this->callbacks.mode, widget - WID_PW_MODE_ALL)) { |
| 399 | /* Enabling used or saved filters automatically enables all. */ |
| 400 | SetBit(this->callbacks.mode, PFM_ALL); |
| 401 | } |
| 402 | this->InvalidateData({PickerInvalidation::Class, PickerInvalidation::Type, PickerInvalidation::Position}); |
| 403 | SndClickBeep(); |
| 404 | break; |
| 405 | |
| 406 | case WID_PW_SHRINK: |
| 407 | this->callbacks.preview_height = this->preview_height = _ctrl_pressed ? PREVIEW_HEIGHT : std::max(PREVIEW_HEIGHT, this->preview_height - STEP_PREVIEW_HEIGHT); |
| 408 | this->InvalidateData({}); |
| 409 | this->ReInit(); |
| 410 | break; |
| 411 | |
| 412 | case WID_PW_EXPAND: |
| 413 | this->callbacks.preview_height = this->preview_height = _ctrl_pressed ? MAX_PREVIEW_HEIGHT : std::min(MAX_PREVIEW_HEIGHT, this->preview_height + STEP_PREVIEW_HEIGHT); |
| 414 | this->InvalidateData({}); |
| 415 | this->ReInit(); |
| 416 | break; |
| 417 | |
| 418 | /* Type Picker */ |
| 419 | case WID_PW_TYPE_ITEM: { |
| 420 | int sel = this->GetWidget<NWidgetBase>(widget)->GetParentWidget<NWidgetMatrix>()->GetCurrentElement(); |
| 421 | assert(sel < (int)this->types.size()); |
| 422 | const auto &item = this->types[sel]; |
| 423 | |
| 424 | if (_ctrl_pressed) { |
| 425 | auto it = this->callbacks.saved.find(item); |
| 426 | if (it == std::end(this->callbacks.saved)) { |
| 427 | this->callbacks.saved.insert(item); |
| 428 | } else { |
| 429 | this->callbacks.saved.erase(it); |
| 430 | } |
| 431 | this->InvalidateData(PickerInvalidation::Type); |
| 432 | break; |
no test coverage detected