* Update the given list position as if it were on this scroll bar when the given keycode was pressed. * This does not update the actual position of this scroll bar, that is left to the caller. It does, * however use the capacity and count of the scroll bar for the bounds and amount to scroll. * * When the count is 0 or the return is ES_NOT_HANDLED, then the position is not updated. * With WKC
| 2472 | * @return ES_NOT_HANDLED when another key than the 6 specific keys was pressed, otherwise ES_HANDLED. |
| 2473 | */ |
| 2474 | EventState Scrollbar::UpdateListPositionOnKeyPress(int &list_position, uint16_t keycode) const |
| 2475 | { |
| 2476 | int new_pos = list_position; |
| 2477 | switch (keycode) { |
| 2478 | case WKC_UP: |
| 2479 | /* scroll up by one */ |
| 2480 | new_pos--; |
| 2481 | break; |
| 2482 | |
| 2483 | case WKC_DOWN: |
| 2484 | /* scroll down by one */ |
| 2485 | new_pos++; |
| 2486 | break; |
| 2487 | |
| 2488 | case WKC_PAGEUP: |
| 2489 | /* scroll up a page */ |
| 2490 | new_pos -= this->GetCapacity(); |
| 2491 | break; |
| 2492 | |
| 2493 | case WKC_PAGEDOWN: |
| 2494 | /* scroll down a page */ |
| 2495 | new_pos += this->GetCapacity(); |
| 2496 | break; |
| 2497 | |
| 2498 | case WKC_HOME: |
| 2499 | /* jump to beginning */ |
| 2500 | new_pos = 0; |
| 2501 | break; |
| 2502 | |
| 2503 | case WKC_END: |
| 2504 | /* jump to end */ |
| 2505 | new_pos = this->GetCount() - 1; |
| 2506 | break; |
| 2507 | |
| 2508 | default: |
| 2509 | return ES_NOT_HANDLED; |
| 2510 | } |
| 2511 | |
| 2512 | /* If there are no elements, there is nothing to scroll/update. */ |
| 2513 | if (this->GetCount() != 0) { |
| 2514 | list_position = Clamp(new_pos, 0, this->GetCount() - 1); |
| 2515 | } |
| 2516 | return ES_HANDLED; |
| 2517 | } |
| 2518 | |
| 2519 | |
| 2520 | /** |
no test coverage detected