| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | |||
| 29 | #include "gate/ui/spinners.hpp" | ||
| 30 | |||
| 31 | namespace gate | ||
| 32 | { | ||
| 33 | namespace ui | ||
| 34 | { | ||
| 35 | |||
| 36 | 1 | Spinbox::Spinbox() | |
| 37 | 1 | : Control(&impl.ctrl) | |
| 38 | { | ||
| 39 | 1 | Mem::clear(&this->impl, sizeof(this->impl)); | |
| 40 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_ui_ctrl_init(&this->impl.ctrl); |
| 41 | 1 | } | |
| 42 | |||
| 43 | 2 | Spinbox::~Spinbox() noexcept | |
| 44 | { | ||
| 45 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
2 | if (this->isCreated()) |
| 46 | { | ||
| 47 | ✗ | this->destroy(); | |
| 48 | } | ||
| 49 | 2 | } | |
| 50 | |||
| 51 | 1 | void Spinbox::create(ControlContainer& parent, Position const& pose, uint32_t flags) | |
| 52 | { | ||
| 53 | 1 | this->failIfCreated("Spinbox::create"); | |
| 54 | |||
| 55 | 1 | result_t result = gate_ui_spinbox_create(&this->impl, *parent, &pose, flags, this); | |
| 56 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 57 | |||
| 58 | 1 | this->impl.on_change = &Spinbox::on_change; | |
| 59 | |||
| 60 | 1 | this->attachNativeControl(&this->impl.ctrl); | |
| 61 | 1 | } | |
| 62 | |||
| 63 | 1 | void Spinbox::setMinimum(int64_t value) | |
| 64 | { | ||
| 65 | 1 | this->failIfNotCreated("Spinbox::setMinimum"); | |
| 66 | 1 | result_t result = gate_ui_spinbox_set_limits(&this->impl, &value, NULL); | |
| 67 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 68 | 1 | } | |
| 69 | 1 | void Spinbox::setMaximum(int64_t value) | |
| 70 | { | ||
| 71 | 1 | this->failIfNotCreated("Spinbox::setMaximum"); | |
| 72 | 1 | result_t result = gate_ui_spinbox_set_limits(&this->impl, NULL, &value); | |
| 73 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 74 | 1 | } | |
| 75 | 1 | void Spinbox::setMinMax(int64_t minimum, int64_t maximum) | |
| 76 | { | ||
| 77 | 1 | this->failIfNotCreated("Spinbox::setMinMax"); | |
| 78 | 1 | result_t result = gate_ui_spinbox_set_limits(&this->impl, &minimum, &maximum); | |
| 79 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 80 | 1 | } | |
| 81 | 1 | void Spinbox::setValue(int64_t value) | |
| 82 | { | ||
| 83 | 1 | this->failIfNotCreated("Spinbox::setValue"); | |
| 84 | 1 | result_t result = gate_ui_spinbox_set_value(&this->impl, value); | |
| 85 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 86 | 1 | } | |
| 87 | 1 | int64_t Spinbox::getMinimum() | |
| 88 | { | ||
| 89 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | this->failIfNotCreated("Spinbox::getMinimum"); |
| 90 | 1 | int64_t ret = 0; | |
| 91 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_ui_spinbox_get_limits(&this->impl, &ret, NULL); |
| 92 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 93 | 1 | return ret; | |
| 94 | } | ||
| 95 | 1 | int64_t Spinbox::getMaximum() | |
| 96 | { | ||
| 97 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | this->failIfNotCreated("Spinbox::getMaximum"); |
| 98 | 1 | int64_t ret = 0; | |
| 99 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_ui_spinbox_get_limits(&this->impl, NULL, &ret); |
| 100 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 101 | 1 | return ret; | |
| 102 | } | ||
| 103 | 1 | void Spinbox::getMinMax(int64_t& minimum, int64_t& maximum) | |
| 104 | { | ||
| 105 | 1 | this->failIfNotCreated("Spinbox::getMinMax"); | |
| 106 | 1 | result_t result = gate_ui_spinbox_get_limits(&this->impl, &minimum, &maximum); | |
| 107 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 108 | 1 | } | |
| 109 | 1 | int64_t Spinbox::getValue() | |
| 110 | { | ||
| 111 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | this->failIfNotCreated("Spinbox::getValue"); |
| 112 | 1 | int64_t ret = 0; | |
| 113 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_ui_spinbox_get_value(&this->impl, &ret); |
| 114 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 115 | 1 | return ret; | |
| 116 | } | ||
| 117 | |||
| 118 | |||
| 119 | ✗ | void Spinbox::onChange(int64_t value) | |
| 120 | { | ||
| 121 | ChangeArg arg; | ||
| 122 | ✗ | arg.Value = value; | |
| 123 | ✗ | this->ChangeEvent(this, &arg); | |
| 124 | ✗ | } | |
| 125 | |||
| 126 | ✗ | void Spinbox::on_change(gate_ui_ctrl_t* sender, gate_int64_t value) | |
| 127 | { | ||
| 128 | ✗ | Spinbox* spinbox = static_cast<Spinbox*>(gate_ui_ctrl_get_userparam(sender)); | |
| 129 | ✗ | if (spinbox != NULL) | |
| 130 | { | ||
| 131 | try | ||
| 132 | { | ||
| 133 | ✗ | spinbox->onChange(value); | |
| 134 | } | ||
| 135 | ✗ | catch (...) {} | |
| 136 | } | ||
| 137 | ✗ | } | |
| 138 | |||
| 139 | |||
| 140 | |||
| 141 | } // end of namespace ui | ||
| 142 | } // end of namespace gate | ||
| 143 |