| 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/forms.hpp" | ||
| 30 | |||
| 31 | namespace gate | ||
| 32 | { | ||
| 33 | namespace ui | ||
| 34 | { | ||
| 35 | |||
| 36 | uint32_t const Form::Flag_Minimizable = GATE_UI_FLAG_FORM_MINIMIZABLE; | ||
| 37 | uint32_t const Form::Flag_Maximizable = GATE_UI_FLAG_FORM_MAXIMIZABLE; | ||
| 38 | uint32_t const Form::Flag_FullScreen = GATE_UI_FLAG_FORM_FULLSCREEN; | ||
| 39 | uint32_t const Form::Flag_NoClose = GATE_UI_FLAG_FORM_NOCLOSE; | ||
| 40 | uint32_t const Form::Flag_DialogStyle = GATE_UI_FLAG_FORM_DIALOGSTYLE; | ||
| 41 | |||
| 42 | |||
| 43 | 1 | Form::Form() | |
| 44 | 1 | : ControlContainer(&impl.ctrl) | |
| 45 | { | ||
| 46 | 1 | Mem::clear(&this->impl, sizeof(this->impl)); | |
| 47 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_ui_ctrl_init(&this->impl.ctrl); |
| 48 | 1 | } | |
| 49 | 2 | Form::~Form() noexcept | |
| 50 | { | ||
| 51 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
2 | if (this->isCreated()) |
| 52 | { | ||
| 53 | ✗ | this->destroy(); | |
| 54 | } | ||
| 55 | 2 | } | |
| 56 | |||
| 57 | 1 | void Form::create(Host& host, Position const* position, String const& title, uint32_t flags) | |
| 58 | { | ||
| 59 | 1 | this->failIfCreated("Form::create"); | |
| 60 | 1 | result_t result = gate_ui_form_create(&this->impl, *host, position, title.c_impl(), flags, NULL, this); | |
| 61 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 62 | |||
| 63 | 1 | this->impl.on_move = &Form::on_move; | |
| 64 | 1 | this->impl.on_resize = &Form::on_resize; | |
| 65 | 1 | this->impl.on_close = &Form::on_close; | |
| 66 | 1 | this->impl.on_menu = &Form::on_menu; | |
| 67 | |||
| 68 | 1 | this->attachNativeControl(&this->impl.ctrl); | |
| 69 | 1 | } | |
| 70 | |||
| 71 | ✗ | void Form::create(Form& owner, Position const* position, String const& title, uint32_t flags) | |
| 72 | { | ||
| 73 | ✗ | this->failIfCreated("Form::create"); | |
| 74 | ✗ | if (!owner.isCreated()) | |
| 75 | { | ||
| 76 | ✗ | GATEXX_RAISE_ERROR(results::InvalidState); | |
| 77 | } | ||
| 78 | ✗ | gate_ui_host_t* ptrHost = gate_ui_ctrl_get_host(owner.c_impl()); | |
| 79 | |||
| 80 | ✗ | result_t result = gate_ui_form_create(&this->impl, ptrHost, position, &*title, flags, | |
| 81 | ✗ | reinterpret_cast<gate_ui_form_t*>(owner.c_impl()), this); | |
| 82 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 83 | |||
| 84 | ✗ | this->impl.on_move = &Form::on_move; | |
| 85 | ✗ | this->impl.on_resize = &Form::on_resize; | |
| 86 | ✗ | this->impl.on_close = &Form::on_close; | |
| 87 | ✗ | this->impl.on_menu = &Form::on_menu; | |
| 88 | |||
| 89 | ✗ | this->attachNativeControl(&this->impl.ctrl); | |
| 90 | ✗ | } | |
| 91 | |||
| 92 | ✗ | void Form::activate() | |
| 93 | { | ||
| 94 | ✗ | this->failIfNotCreated("Form::activate"); | |
| 95 | ✗ | result_t result = gate_ui_form_activate(&this->impl); | |
| 96 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 97 | ✗ | } | |
| 98 | |||
| 99 | ✗ | void Form::refresh() | |
| 100 | { | ||
| 101 | ✗ | this->failIfNotCreated("Form::refresh"); | |
| 102 | ✗ | result_t result = gate_ui_form_refresh(&this->impl); | |
| 103 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 104 | ✗ | } | |
| 105 | |||
| 106 | 1 | void Form::setMenu(Menu const* menu) | |
| 107 | { | ||
| 108 | 1 | this->failIfNotCreated("Form::setMenu"); | |
| 109 | 1 | result_t result = gate_ui_form_set_menu(&this->impl, menu); | |
| 110 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 111 | 1 | } | |
| 112 | 1 | void Form::setLayout(Layout const* layout) | |
| 113 | { | ||
| 114 | 1 | result_t result = gate_ui_form_set_layout(&this->impl, layout); | |
| 115 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 116 | 1 | } | |
| 117 | |||
| 118 | ✗ | void Form::on_move(gate_ui_ctrl_t* sender, gate_ui_point_t const* position) | |
| 119 | { | ||
| 120 | ✗ | Form* form = static_cast<Form*>(gate_ui_ctrl_get_userparam(sender)); | |
| 121 | ✗ | if ((form != NULL) && (position != NULL)) | |
| 122 | { | ||
| 123 | try | ||
| 124 | { | ||
| 125 | ✗ | form->onMove(*position); | |
| 126 | } | ||
| 127 | ✗ | catch (...) {} | |
| 128 | } | ||
| 129 | ✗ | } | |
| 130 | ✗ | void Form::on_resize(gate_ui_ctrl_t* sender, gate_ui_size_t const* size) | |
| 131 | { | ||
| 132 | ✗ | Form* form = static_cast<Form*>(gate_ui_ctrl_get_userparam(sender)); | |
| 133 | ✗ | if ((form != NULL) && (size != NULL)) | |
| 134 | { | ||
| 135 | try | ||
| 136 | { | ||
| 137 | ✗ | form->onResize(*size); | |
| 138 | } | ||
| 139 | ✗ | catch (...) {} | |
| 140 | } | ||
| 141 | ✗ | } | |
| 142 | ✗ | void Form::on_close(gate_ui_ctrl_t* sender) | |
| 143 | { | ||
| 144 | ✗ | Form* form = static_cast<Form*>(gate_ui_ctrl_get_userparam(sender)); | |
| 145 | ✗ | if ((form != NULL)) | |
| 146 | { | ||
| 147 | try | ||
| 148 | { | ||
| 149 | ✗ | form->onClose(); | |
| 150 | } | ||
| 151 | ✗ | catch (...) {} | |
| 152 | } | ||
| 153 | ✗ | } | |
| 154 | ✗ | void Form::on_menu(gate_ui_ctrl_t* sender, gate_ui_menu_entry const* menuentry) | |
| 155 | { | ||
| 156 | ✗ | Form* form = static_cast<Form*>(gate_ui_ctrl_get_userparam(sender)); | |
| 157 | ✗ | if ((form != NULL) && (menuentry != NULL)) | |
| 158 | { | ||
| 159 | try | ||
| 160 | { | ||
| 161 | ✗ | form->onMenu(*menuentry); | |
| 162 | } | ||
| 163 | ✗ | catch (...) {} | |
| 164 | } | ||
| 165 | ✗ | } | |
| 166 | |||
| 167 | |||
| 168 | ✗ | void Form::onMove(gate_ui_point_t const& position) | |
| 169 | { | ||
| 170 | ✗ | PointArg arg(position.x, position.y); | |
| 171 | ✗ | this->MoveEvent(this, &arg); | |
| 172 | ✗ | } | |
| 173 | ✗ | void Form::onResize(gate_ui_size_t const& size) | |
| 174 | { | ||
| 175 | ✗ | SizeArg arg(size.width, size.height); | |
| 176 | ✗ | this->ResizeEvent(this, &arg); | |
| 177 | ✗ | } | |
| 178 | ✗ | void Form::onClose() | |
| 179 | { | ||
| 180 | EventArg arg; | ||
| 181 | ✗ | this->CloseEvent(this, &arg); | |
| 182 | ✗ | } | |
| 183 | ✗ | void Form::onMenu(Menu::entry_t const& menuentry) | |
| 184 | { | ||
| 185 | ✗ | MenuArg arg(menuentry); | |
| 186 | ✗ | this->MenuEvent(this, &arg); | |
| 187 | ✗ | } | |
| 188 | |||
| 189 | ✗ | void Form::beginDialog() | |
| 190 | { | ||
| 191 | ✗ | result_t result = gate_ui_form_begin_dialog(&this->impl); | |
| 192 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 193 | ✗ | } | |
| 194 | ✗ | void Form::endDialog() | |
| 195 | { | ||
| 196 | ✗ | result_t result = gate_ui_form_end_dialog(&this->impl); | |
| 197 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 198 | ✗ | } | |
| 199 | |||
| 200 | } // end of namespace ui | ||
| 201 | |||
| 202 | } // end of namespace gate | ||
| 203 |