| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2025, 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 | ✗ | Spinbox::Spinbox() | |
| 37 | ✗ | : Control(&impl.ctrl) | |
| 38 | { | ||
| 39 | ✗ | Mem::clear(&this->impl, sizeof(this->impl)); | |
| 40 | ✗ | gate_ui_ctrl_init(&this->impl.ctrl); | |
| 41 | ✗ | } | |
| 42 | |||
| 43 | ✗ | Spinbox::~Spinbox() noexcept | |
| 44 | { | ||
| 45 | ✗ | if (this->isCreated()) | |
| 46 | { | ||
| 47 | ✗ | this->destroy(); | |
| 48 | } | ||
| 49 | ✗ | } | |
| 50 | |||
| 51 | ✗ | void Spinbox::create(ControlContainer& parent, Position const& pose, uint32_t flags) | |
| 52 | { | ||
| 53 | ✗ | this->failIfCreated("Spinbox::create"); | |
| 54 | |||
| 55 | ✗ | result_t result = gate_ui_spinbox_create(&this->impl, *parent, &pose, flags, this); | |
| 56 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 57 | |||
| 58 | ✗ | this->impl.on_change = &Spinbox::on_change; | |
| 59 | |||
| 60 | ✗ | this->attachNativeControl(&this->impl.ctrl); | |
| 61 | ✗ | } | |
| 62 | |||
| 63 | ✗ | void Spinbox::setMinimum(int64_t value) | |
| 64 | { | ||
| 65 | ✗ | this->failIfNotCreated("Spinbox::setMinimum"); | |
| 66 | ✗ | result_t result = gate_ui_spinbox_set_limits(&this->impl, &value, NULL); | |
| 67 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 68 | ✗ | } | |
| 69 | ✗ | void Spinbox::setMaximum(int64_t value) | |
| 70 | { | ||
| 71 | ✗ | this->failIfNotCreated("Spinbox::setMaximum"); | |
| 72 | ✗ | result_t result = gate_ui_spinbox_set_limits(&this->impl, NULL, &value); | |
| 73 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 74 | ✗ | } | |
| 75 | ✗ | void Spinbox::setMinMax(int64_t minimum, int64_t maximum) | |
| 76 | { | ||
| 77 | ✗ | this->failIfNotCreated("Spinbox::setMinMax"); | |
| 78 | ✗ | result_t result = gate_ui_spinbox_set_limits(&this->impl, &minimum, &maximum); | |
| 79 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 80 | ✗ | } | |
| 81 | ✗ | void Spinbox::setValue(int64_t value) | |
| 82 | { | ||
| 83 | ✗ | this->failIfNotCreated("Spinbox::setValue"); | |
| 84 | ✗ | result_t result = gate_ui_spinbox_set_value(&this->impl, value); | |
| 85 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 86 | ✗ | } | |
| 87 | ✗ | int64_t Spinbox::getMinimum() | |
| 88 | { | ||
| 89 | ✗ | this->failIfNotCreated("Spinbox::getMinimum"); | |
| 90 | ✗ | int64_t ret = 0; | |
| 91 | ✗ | result_t result = gate_ui_spinbox_get_limits(&this->impl, &ret, NULL); | |
| 92 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 93 | ✗ | return ret; | |
| 94 | } | ||
| 95 | ✗ | int64_t Spinbox::getMaximum() | |
| 96 | { | ||
| 97 | ✗ | this->failIfNotCreated("Spinbox::getMaximum"); | |
| 98 | ✗ | int64_t ret = 0; | |
| 99 | ✗ | result_t result = gate_ui_spinbox_get_limits(&this->impl, NULL, &ret); | |
| 100 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 101 | ✗ | return ret; | |
| 102 | } | ||
| 103 | ✗ | void Spinbox::getMinMax(int64_t& minimum, int64_t& maximum) | |
| 104 | { | ||
| 105 | ✗ | this->failIfNotCreated("Spinbox::getMinMax"); | |
| 106 | ✗ | result_t result = gate_ui_spinbox_get_limits(&this->impl, &minimum, &maximum); | |
| 107 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 108 | ✗ | } | |
| 109 | ✗ | int64_t Spinbox::getValue() | |
| 110 | { | ||
| 111 | ✗ | this->failIfNotCreated("Spinbox::getValue"); | |
| 112 | ✗ | int64_t ret = 0; | |
| 113 | ✗ | result_t result = gate_ui_spinbox_get_value(&this->impl, &ret); | |
| 114 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 115 | ✗ | 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 |