| 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/gateui.hpp" | ||
| 30 | #include "gate/exceptions.hpp" | ||
| 31 | |||
| 32 | namespace gate | ||
| 33 | { | ||
| 34 | namespace ui | ||
| 35 | { | ||
| 36 | |||
| 37 | uint32_t const Input::Key_Alt = GATE_UI_KEY_ALT; | ||
| 38 | uint32_t const Input::Key_Ctrl = GATE_UI_KEY_CTRL; | ||
| 39 | uint32_t const Input::Key_Shift = GATE_UI_KEY_SHIFT; | ||
| 40 | |||
| 41 | uint32_t const Input::Mouse_Left = GATE_UI_MOUSE_LEFT; | ||
| 42 | uint32_t const Input::Mouse_Right = GATE_UI_MOUSE_RIGHT; | ||
| 43 | uint32_t const Input::Mouse_Middle = GATE_UI_MOUSE_MIDDLE; | ||
| 44 | |||
| 45 | /////////////////////////// | ||
| 46 | // // | ||
| 47 | // Host implementation // | ||
| 48 | // // | ||
| 49 | /////////////////////////// | ||
| 50 | |||
| 51 | uint32_t const Host::Color_Background = GATE_UI_COLOR_BACKGROUND; | ||
| 52 | uint32_t const Host::Color_Workspace = GATE_UI_COLOR_WORKSPACE; | ||
| 53 | uint32_t const Host::Color_Window = GATE_UI_COLOR_WINDOW; | ||
| 54 | uint32_t const Host::Color_WindowText = GATE_UI_COLOR_WINDOWTEXT; | ||
| 55 | uint32_t const Host::Color_WindowTextDisabled = GATE_UI_COLOR_WINDOWTEXTDISABLED; | ||
| 56 | uint32_t const Host::Color_Control = GATE_UI_COLOR_CONTROL; | ||
| 57 | uint32_t const Host::Color_ControlText = GATE_UI_COLOR_CONTROLTEXT; | ||
| 58 | uint32_t const Host::Color_ControlTextDisabled = GATE_UI_COLOR_CONTROLTEXTDISABLED; | ||
| 59 | uint32_t const Host::Color_ControlBorderLight = GATE_UI_COLOR_CONTROLBORDERLIGHT; | ||
| 60 | uint32_t const Host::Color_ControlBorderHiLight = GATE_UI_COLOR_CONTROLBORDERHILIGHT; | ||
| 61 | uint32_t const Host::Color_ControlBorderShadow = GATE_UI_COLOR_CONTROLBORDERSHADOW; | ||
| 62 | uint32_t const Host::Color_ControlBorderDarkShadow = GATE_UI_COLOR_CONTROLBORDERDARKSHADOW; | ||
| 63 | uint32_t const Host::Color_MenuBackground = GATE_UI_COLOR_MENUBACKGROUND; | ||
| 64 | uint32_t const Host::Color_MenuText = GATE_UI_COLOR_MENUTEXT; | ||
| 65 | uint32_t const Host::Color_SelectedMenuBackground = GATE_UI_COLOR_SELECTEDMENUBACKGROUND; | ||
| 66 | uint32_t const Host::Color_SelectedMenuText = GATE_UI_COLOR_SELECTEDMENUTEXT; | ||
| 67 | |||
| 68 | uint32_t const Host::FontType_Standard = GATE_UI_FONT_TYPE_STANDARD; | ||
| 69 | uint32_t const Host::FontType_SansSerif = GATE_UI_FONT_TYPE_SANSSERIF; | ||
| 70 | uint32_t const Host::FontType_Serif = GATE_UI_FONT_TYPE_SERIF; | ||
| 71 | uint32_t const Host::FontType_Monospace = GATE_UI_FONT_TYPE_MONOSPACE; | ||
| 72 | |||
| 73 | ✗ | Host::Host() | |
| 74 | ✗ | : ptr(NULL) | |
| 75 | { | ||
| 76 | ✗ | } | |
| 77 | |||
| 78 | 1 | void Host::init(uintptr_t appHandle) | |
| 79 | { | ||
| 80 | 1 | gate_result_t result = gate_ui_host_init(&this->impl, appHandle, this); | |
| 81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 82 | 1 | this->ptr = &this->impl; | |
| 83 | 1 | } | |
| 84 | |||
| 85 | |||
| 86 | 1 | Host::Host(uintptr_t appHandle) | |
| 87 | 1 | : ptr(NULL) | |
| 88 | { | ||
| 89 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | this->init(appHandle); |
| 90 | 1 | } | |
| 91 | |||
| 92 | 2 | Host::~Host() noexcept | |
| 93 | { | ||
| 94 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
2 | if (this->ptr) |
| 95 | { | ||
| 96 | 2 | gate_ui_host_uninit(this->ptr); | |
| 97 | } | ||
| 98 | 2 | } | |
| 99 | |||
| 100 | 1 | Host& Host::getHost(Control& ctrl) | |
| 101 | { | ||
| 102 | 1 | gate_ui_ctrl_t* ptr_ctrl = ctrl.c_impl(); | |
| 103 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!ptr_ctrl) |
| 104 | { | ||
| 105 | ✗ | GATEXX_RAISE_ERROR(results::NullPointer); | |
| 106 | } | ||
| 107 | 1 | gate_ui_host_t* ptr_host = gate_ui_ctrl_get_host(ptr_ctrl); | |
| 108 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!ptr_host) |
| 109 | { | ||
| 110 | ✗ | GATEXX_RAISE_ERROR(results::NullPointer); | |
| 111 | } | ||
| 112 | 1 | return Host::getHost(*ptr_host); | |
| 113 | } | ||
| 114 | |||
| 115 | 1 | Host& Host::getHost(gate_ui_host_t& hostImpl) | |
| 116 | { | ||
| 117 | 1 | void* obj_ptr = gate_ui_host_get_userparam(&hostImpl); | |
| 118 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!obj_ptr) |
| 119 | { | ||
| 120 | ✗ | GATEXX_RAISE_ERROR(results::NullPointer); | |
| 121 | } | ||
| 122 | 1 | return *static_cast<Host*>(obj_ptr); | |
| 123 | } | ||
| 124 | |||
| 125 | |||
| 126 | 1 | void Host::run() | |
| 127 | { | ||
| 128 | 1 | gate_ui_host_run(this->c_impl()); | |
| 129 | 1 | } | |
| 130 | |||
| 131 | 1 | void Host::quit() | |
| 132 | { | ||
| 133 | 1 | gate_ui_host_quit(this->c_impl()); | |
| 134 | 1 | } | |
| 135 | |||
| 136 | 1 | uint32_t Host::getLineHeight() | |
| 137 | { | ||
| 138 | 1 | return gate_ui_host_default_line_height(this->c_impl()); | |
| 139 | } | ||
| 140 | 2 | uint32_t Host::getControlHeight(uint32_t lines) | |
| 141 | { | ||
| 142 | 2 | return gate_ui_host_default_control_height(this->c_impl(), lines); | |
| 143 | } | ||
| 144 | |||
| 145 | 1 | int32_t Host::getUnitLength(real32_t units) | |
| 146 | { | ||
| 147 | 1 | real32_t controlHeight = static_cast<real32_t>(this->getControlHeight()); | |
| 148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | return static_cast<int32_t>(controlHeight * units + (units < 0.0f ? -0.5f : 0.5f)); |
| 149 | } | ||
| 150 | |||
| 151 | |||
| 152 | ✗ | Color Host::getDefaultColor(uint32_t colortype) | |
| 153 | { | ||
| 154 | ✗ | Color ret; | |
| 155 | ✗ | result_t res = gate_ui_host_default_color(this->c_impl(), colortype, &ret.value); | |
| 156 | ✗ | GATEXX_CHECK_ERROR(res); | |
| 157 | ✗ | return ret; | |
| 158 | } | ||
| 159 | |||
| 160 | 2 | Font Host::getDefaultFont(uint32_t fonttype) | |
| 161 | { | ||
| 162 | 2 | result_t res = GATE_RESULT_OK; | |
| 163 | 2 | Font fnt; | |
| 164 | 2 | gate_ui_font_t* ptrfnt = &fnt; | |
| 165 | 2 | res = gate_ui_host_default_font(this->c_impl(), fonttype, ptrfnt); | |
| 166 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_ERROR(res); |
| 167 | 2 | return fnt; | |
| 168 | } | ||
| 169 | 1 | int32_t Host::getPixelsOfPoints(real32_t points) | |
| 170 | { | ||
| 171 | 1 | return gate_ui_host_get_pixels_in_points(this->c_impl(), points); | |
| 172 | } | ||
| 173 | 1 | real32_t Host::getPointsOfPixels(int32_t pixels) | |
| 174 | { | ||
| 175 | 1 | return gate_ui_host_get_points_in_pixels(this->c_impl(), pixels); | |
| 176 | } | ||
| 177 | |||
| 178 | |||
| 179 | ✗ | static bool_t GATE_CALL gate_ui_host_get_fonts_cb(char const* font_name, void* userparam) | |
| 180 | { | ||
| 181 | ✗ | ArrayList<String>* ptr = static_cast<ArrayList<String>*>(userparam); | |
| 182 | ✗ | ptr->add(String(font_name)); | |
| 183 | ✗ | return true; | |
| 184 | } | ||
| 185 | |||
| 186 | ✗ | Array<String> Host::getFonts() | |
| 187 | { | ||
| 188 | ✗ | ArrayList<String> ret; | |
| 189 | ✗ | gate_ui_host_enum_fonts(this->c_impl(), &gate_ui_host_get_fonts_cb, &ret); | |
| 190 | ✗ | return ret.toArray(); | |
| 191 | } | ||
| 192 | |||
| 193 | |||
| 194 | ✗ | String Host::getClipboardText() | |
| 195 | { | ||
| 196 | gate_string_t text; | ||
| 197 | ✗ | result_t res = gate_ui_host_clipboard_get_text(this->c_impl(), &text); | |
| 198 | ✗ | GATEXX_CHECK_EXCEPTION(res); | |
| 199 | ✗ | return String::createFrom(text); | |
| 200 | } | ||
| 201 | ✗ | bool Host::getClipboardText(String& text) | |
| 202 | { | ||
| 203 | gate_string_t str; | ||
| 204 | ✗ | result_t res = gate_ui_host_clipboard_get_text(this->c_impl(), &str); | |
| 205 | ✗ | if (GATE_SUCCEEDED(res)) | |
| 206 | { | ||
| 207 | ✗ | text = String::createFrom(str); | |
| 208 | ✗ | return true; | |
| 209 | } | ||
| 210 | ✗ | text = String(); | |
| 211 | ✗ | return false; | |
| 212 | } | ||
| 213 | |||
| 214 | |||
| 215 | ✗ | void Host::setClipboardText(String const& text) | |
| 216 | { | ||
| 217 | ✗ | result_t res = gate_ui_host_clipboard_set_text(this->c_impl(), text.c_impl()); | |
| 218 | ✗ | GATEXX_CHECK_EXCEPTION(res); | |
| 219 | ✗ | } | |
| 220 | |||
| 221 | ✗ | Position Host::getDefaultWorkarea() | |
| 222 | { | ||
| 223 | ✗ | Position ret; | |
| 224 | ✗ | result_t result = gate_ui_host_default_workarea(this->c_impl(), &ret); | |
| 225 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 226 | ✗ | return ret; | |
| 227 | } | ||
| 228 | ✗ | Position Host::getTotalWorkarea() | |
| 229 | { | ||
| 230 | ✗ | Position ret; | |
| 231 | ✗ | result_t result = gate_ui_host_total_workarea(this->c_impl(), &ret); | |
| 232 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 233 | ✗ | return ret; | |
| 234 | } | ||
| 235 | |||
| 236 | 1 | void Host::execute(Runnable const& code) | |
| 237 | { | ||
| 238 | 1 | result_t const result = gate_ui_host_execute(this->c_impl(), code.c_impl()); | |
| 239 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 240 | 1 | } | |
| 241 | |||
| 242 | 1 | void Host::processEvents() | |
| 243 | { | ||
| 244 | 1 | result_t const result = gate_ui_host_process_events(this->c_impl()); | |
| 245 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 246 | 1 | } | |
| 247 | |||
| 248 | 1 | gate_ui_host_t* Host::operator*() | |
| 249 | { | ||
| 250 | 1 | return this->ptr; | |
| 251 | } | ||
| 252 | ✗ | gate_ui_host_t const* Host::operator*() const | |
| 253 | { | ||
| 254 | ✗ | return this->ptr; | |
| 255 | } | ||
| 256 | 18 | gate_ui_host_t* Host::c_impl() | |
| 257 | { | ||
| 258 | 18 | return this->ptr; | |
| 259 | } | ||
| 260 | ✗ | gate_ui_host_t const* Host::c_impl() const | |
| 261 | { | ||
| 262 | ✗ | return this->ptr; | |
| 263 | } | ||
| 264 | |||
| 265 | |||
| 266 | |||
| 267 | |||
| 268 | ////////////////////////////// | ||
| 269 | // // | ||
| 270 | // Control implementation // | ||
| 271 | // // | ||
| 272 | ////////////////////////////// | ||
| 273 | |||
| 274 | uint32_t const Control::Flag_Enabled = GATE_UI_FLAG_ENABLED; | ||
| 275 | uint32_t const Control::Flag_Visible = GATE_UI_FLAG_VISIBLE; | ||
| 276 | uint32_t const Control::Flag_Resizable = GATE_UI_FLAG_RESIZABLE; | ||
| 277 | |||
| 278 | enumint_t const Control::Action_Activate = GATE_UI_ACTION_ACTIVATE; | ||
| 279 | enumint_t const Control::Action_ContextMenu = GATE_UI_ACTION_CONTEXTMENU; | ||
| 280 | enumint_t const Control::Action_KeyPress = GATE_UI_ACTION_KEYPRESS; | ||
| 281 | |||
| 282 | 116 | Control::~Control() noexcept | |
| 283 | { | ||
| 284 | 58 | this->destroy(); | |
| 285 | 58 | } | |
| 286 | |||
| 287 | 21 | gate_ui_ctrl_t* Control::operator*() const | |
| 288 | { | ||
| 289 | 21 | return this->ctrl; | |
| 290 | } | ||
| 291 | |||
| 292 | |||
| 293 | 36 | void Control::destroy() noexcept | |
| 294 | { | ||
| 295 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 13 times.
|
36 | if (this->ctrl != NULL) |
| 296 | { | ||
| 297 | 23 | gate_ui_ctrl_destroy(this->ctrl); | |
| 298 | 23 | this->ctrl = NULL; | |
| 299 | } | ||
| 300 | 36 | } | |
| 301 | |||
| 302 | 1 | Control* Control::getParent() const | |
| 303 | { | ||
| 304 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (this->ctrl != NULL) |
| 305 | { | ||
| 306 | 1 | void* ptr = gate_ui_ctrl_get_userparam(this->ctrl); | |
| 307 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (ptr != NULL) |
| 308 | { | ||
| 309 | 1 | return static_cast<Control*>(ptr); | |
| 310 | } | ||
| 311 | } | ||
| 312 | ✗ | return NULL; | |
| 313 | } | ||
| 314 | |||
| 315 | 287 | bool Control::isCreated() const noexcept | |
| 316 | { | ||
| 317 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 262 times.
|
287 | if (this->ctrl == NULL) |
| 318 | { | ||
| 319 | 25 | return false; | |
| 320 | } | ||
| 321 | else | ||
| 322 | { | ||
| 323 | 262 | return gate_ui_ctrl_is_created(this->ctrl); | |
| 324 | } | ||
| 325 | } | ||
| 326 | 3 | bool Control::isEnabled() const | |
| 327 | { | ||
| 328 | 3 | return gate_ui_ctrl_is_enabled(this->ctrl); | |
| 329 | } | ||
| 330 | 3 | bool Control::isFocused() const | |
| 331 | { | ||
| 332 | 3 | return gate_ui_ctrl_is_focused(this->ctrl); | |
| 333 | } | ||
| 334 | 3 | bool Control::isVisible() const | |
| 335 | { | ||
| 336 | 3 | return gate_ui_ctrl_is_visible(this->ctrl); | |
| 337 | } | ||
| 338 | 3 | Position Control::getPosition() const | |
| 339 | { | ||
| 340 | 3 | Position pos; | |
| 341 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | result_t result = gate_ui_ctrl_get_position(this->ctrl, &pos); |
| 342 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
3 | GATEXX_CHECK_ERROR(result); |
| 343 | 3 | return pos; | |
| 344 | } | ||
| 345 | 3 | Size Control::getSize() const | |
| 346 | { | ||
| 347 | 3 | Size sz; | |
| 348 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | result_t result = gate_ui_ctrl_get_size(this->ctrl, &sz); |
| 349 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
3 | GATEXX_CHECK_ERROR(result); |
| 350 | 3 | return sz; | |
| 351 | } | ||
| 352 | 1 | uint32_t Control::getTextLength() const | |
| 353 | { | ||
| 354 | 1 | uint32_t ret = 0; | |
| 355 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_ui_ctrl_get_text_length(this->ctrl, &ret); |
| 356 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
| 357 | 1 | return ret; | |
| 358 | } | ||
| 359 | |||
| 360 | 5 | String Control::getText() const | |
| 361 | { | ||
| 362 | gate_string_t str; | ||
| 363 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | result_t result = gate_ui_ctrl_get_text(this->ctrl, &str); |
| 364 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
5 | GATEXX_CHECK_ERROR(result); |
| 365 | 10 | return String::createFrom(str); | |
| 366 | } | ||
| 367 | 2 | int32_t Control::getState() const | |
| 368 | { | ||
| 369 | 2 | int32_t ret = 0; | |
| 370 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | result_t result = gate_ui_ctrl_get_state(this->ctrl, &ret); |
| 371 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_ERROR(result); |
| 372 | 2 | return ret; | |
| 373 | } | ||
| 374 | |||
| 375 | 3 | void Control::setEnabled(bool enabled) | |
| 376 | { | ||
| 377 | 3 | result_t result = gate_ui_ctrl_set_enabled(this->ctrl, enabled); | |
| 378 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | GATEXX_CHECK_ERROR(result); |
| 379 | 3 | } | |
| 380 | 4 | void Control::setVisible(bool visible) | |
| 381 | { | ||
| 382 | 4 | result_t result = gate_ui_ctrl_set_visible(this->ctrl, visible); | |
| 383 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | GATEXX_CHECK_ERROR(result); |
| 384 | 4 | } | |
| 385 | 3 | void Control::setPosition(Point const* position, Size const* size) | |
| 386 | { | ||
| 387 | 3 | result_t result = gate_ui_ctrl_set_position(this->ctrl, position, size); | |
| 388 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | GATEXX_CHECK_EXCEPTION(result); |
| 389 | 3 | } | |
| 390 | 3 | void Control::setPosition(Position const& pos) | |
| 391 | { | ||
| 392 | 3 | Point pnt(pos.pos); | |
| 393 | 3 | Size sz(pos.size); | |
| 394 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | this->setPosition(&pnt, &sz); |
| 395 | 3 | } | |
| 396 | 2 | void Control::setFocus() | |
| 397 | { | ||
| 398 | 2 | result_t result = gate_ui_ctrl_set_focus(this->ctrl); | |
| 399 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 400 | 2 | } | |
| 401 | |||
| 402 | |||
| 403 | |||
| 404 | 7 | void Control::setText(String const& text) | |
| 405 | { | ||
| 406 | 7 | result_t result = gate_ui_ctrl_set_text(this->ctrl, text.c_impl()); | |
| 407 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | GATEXX_CHECK_EXCEPTION(result); |
| 408 | 7 | } | |
| 409 | 2 | void Control::setState(int32_t state) | |
| 410 | { | ||
| 411 | 2 | result_t result = gate_ui_ctrl_set_state(this->ctrl, state); | |
| 412 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 413 | 2 | } | |
| 414 | |||
| 415 | 29 | Control::Control(gate_ui_ctrl_t* ctrlimpl) | |
| 416 | 29 | : ctrl_impl(ctrlimpl), ctrl(NULL) | |
| 417 | { | ||
| 418 | |||
| 419 | 29 | } | |
| 420 | 25 | gate_ui_ctrl_t* Control::c_impl() const | |
| 421 | { | ||
| 422 | 25 | return this->ctrl_impl; | |
| 423 | } | ||
| 424 | |||
| 425 | 35 | void Control::attachNativeControl(gate_ui_ctrl_t* ctl) | |
| 426 | { | ||
| 427 | 35 | this->ctrl = ctl; | |
| 428 | 35 | } | |
| 429 | |||
| 430 | 23 | void Control::failIfCreated(char const* sourceFunction) | |
| 431 | { | ||
| 432 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
|
23 | if (this->isCreated()) |
| 433 | { | ||
| 434 | ✗ | raiseError(results::InvalidState, | |
| 435 | (sourceFunction == NULL) ? "Control::failIfCreated" : sourceFunction); | ||
| 436 | } | ||
| 437 | 23 | } | |
| 438 | 234 | void Control::failIfNotCreated(char const* sourceFunction) | |
| 439 | { | ||
| 440 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 234 times.
|
234 | if (!this->isCreated()) |
| 441 | { | ||
| 442 | ✗ | raiseError(results::InvalidState, | |
| 443 | (sourceFunction == NULL) ? "Control::failIfNotCreated" : sourceFunction); | ||
| 444 | } | ||
| 445 | 234 | } | |
| 446 | |||
| 447 | |||
| 448 | |||
| 449 | |||
| 450 | /////////////////////////////////////// | ||
| 451 | // // | ||
| 452 | // ControlContainer implementation // | ||
| 453 | // // | ||
| 454 | /////////////////////////////////////// | ||
| 455 | |||
| 456 | 10 | ControlContainer::ControlContainer(gate_ui_ctrl_t* ctrlimpl) | |
| 457 | 10 | : Control(ctrlimpl) | |
| 458 | { | ||
| 459 | |||
| 460 | 10 | } | |
| 461 | 20 | ControlContainer::~ControlContainer() noexcept | |
| 462 | { | ||
| 463 | 20 | } | |
| 464 | |||
| 465 | 1 | Array<Control*> ControlContainer::getChildren() const | |
| 466 | { | ||
| 467 | 1 | Array<Control*> ret; | |
| 468 | //TODO | ||
| 469 | 1 | return ret; | |
| 470 | } | ||
| 471 | |||
| 472 | ✗ | void ControlContainer::setLayout(Layout const* layout) | |
| 473 | { | ||
| 474 | ✗ | } | |
| 475 | |||
| 476 | |||
| 477 | |||
| 478 | ///////////////////////////// | ||
| 479 | // Layout implementation // | ||
| 480 | ///////////////////////////// | ||
| 481 | |||
| 482 | enumint_t const Layout::Type_Auto = GATE_UI_LAYOUT_TYPE_AUTO; | ||
| 483 | enumint_t const Layout::Type_Pixel = GATE_UI_LAYOUT_TYPE_PIXEL; | ||
| 484 | enumint_t const Layout::Type_Percent = GATE_UI_LAYOUT_TYPE_PERCENT; | ||
| 485 | enumint_t const Layout::Type_UnitScale = GATE_UI_LAYOUT_TYPE_UNITSCALE; | ||
| 486 | |||
| 487 | 5 | Layout::Layout() | |
| 488 | { | ||
| 489 | 5 | result_t result = gate_ui_layout_create(this); | |
| 490 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | GATEXX_CHECK_ERROR(result); |
| 491 | 5 | } | |
| 492 | 10 | Layout::~Layout() | |
| 493 | { | ||
| 494 | 5 | gate_ui_layout_destroy(this); | |
| 495 | 5 | } | |
| 496 | |||
| 497 | 5 | void Layout::clear() | |
| 498 | { | ||
| 499 | 5 | gate_ui_layout_clear(this); | |
| 500 | 5 | } | |
| 501 | |||
| 502 | 8 | uint32_t Layout::addColumn(enumint_t type, real32_t value) | |
| 503 | { | ||
| 504 | 8 | gate_uint32_t colindex = gate_ui_layout_get_columns(this); | |
| 505 | 8 | result_t result = gate_ui_layout_add_column(this, type, value); | |
| 506 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | GATEXX_CHECK_ERROR(result); |
| 507 | 8 | return colindex; | |
| 508 | } | ||
| 509 | 14 | uint32_t Layout::addRow(enumint_t type, real32_t value) | |
| 510 | { | ||
| 511 | 14 | gate_uint32_t rowindex = gate_ui_layout_get_rows(this); | |
| 512 | 14 | result_t result = gate_ui_layout_add_row(this, type, value); | |
| 513 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | GATEXX_CHECK_ERROR(result); |
| 514 | 14 | return rowindex; | |
| 515 | } | ||
| 516 | |||
| 517 | 1 | void Layout::setColumn(uint32_t col, enumint_t type, real32_t value) | |
| 518 | { | ||
| 519 | 1 | result_t result = gate_ui_layout_set_column(this, col, type, value); | |
| 520 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 521 | 1 | } | |
| 522 | 2 | void Layout::setRow(uint32_t row, enumint_t type, real32_t value) | |
| 523 | { | ||
| 524 | 2 | result_t result = gate_ui_layout_set_row(this, row, type, value); | |
| 525 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_ERROR(result); |
| 526 | 2 | } | |
| 527 | |||
| 528 | 1 | void Layout::setBorder(uint32_t borderWidth) | |
| 529 | { | ||
| 530 | 1 | this->border = borderWidth; | |
| 531 | 1 | } | |
| 532 | 1 | void Layout::setColumnSpace(uint32_t colSpace) | |
| 533 | { | ||
| 534 | 1 | this->colspace = colSpace; | |
| 535 | 1 | } | |
| 536 | 1 | void Layout::setRowSpace(uint32_t rowSpace) | |
| 537 | { | ||
| 538 | 1 | this->rowspace = rowSpace; | |
| 539 | 1 | } | |
| 540 | |||
| 541 | |||
| 542 | 15 | void Layout::setControl(Control const& ctrl, uint32_t row, uint32_t col, uint32_t rowspan, uint32_t colspan) | |
| 543 | { | ||
| 544 | 15 | result_t result = gate_ui_layout_set_control(this, ctrl.c_impl(), row, col, rowspan, colspan); | |
| 545 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
|
15 | GATEXX_CHECK_ERROR(result); |
| 546 | 15 | } | |
| 547 | |||
| 548 | 2 | bool_t Layout::findControl(Control const& ctrl, uint32_t& row, uint32_t& col) | |
| 549 | { | ||
| 550 | 2 | result_t result = gate_ui_layout_find_control(this, ctrl.c_impl(), &row, &col, NULL, NULL); | |
| 551 | 2 | return GATE_SUCCEEDED(result) ? true : false; | |
| 552 | } | ||
| 553 | |||
| 554 | ✗ | bool_t Layout::changeControlRowHeight(Control const& ctrl, enumint_t type, real32_t height) | |
| 555 | { | ||
| 556 | ✗ | uint32_t row = 0; | |
| 557 | ✗ | result_t result = gate_ui_layout_find_control(this, ctrl.c_impl(), &row, NULL, NULL, NULL); | |
| 558 | ✗ | if (GATE_SUCCEEDED(result)) | |
| 559 | { | ||
| 560 | ✗ | result = gate_ui_layout_set_row(this, row, type, height); | |
| 561 | } | ||
| 562 | ✗ | return GATE_SUCCEEDED(result) ? true : false; | |
| 563 | } | ||
| 564 | |||
| 565 | ✗ | bool_t Layout::changeControlColWidth(Control const& ctrl, enumint_t type, real32_t width) | |
| 566 | { | ||
| 567 | ✗ | uint32_t col = 0; | |
| 568 | ✗ | result_t result = gate_ui_layout_find_control(this, ctrl.c_impl(), NULL, &col, NULL, NULL); | |
| 569 | ✗ | if (GATE_SUCCEEDED(result)) | |
| 570 | { | ||
| 571 | ✗ | result = gate_ui_layout_set_column(this, col, type, width); | |
| 572 | } | ||
| 573 | ✗ | return GATE_SUCCEEDED(result) ? true : false; | |
| 574 | } | ||
| 575 | |||
| 576 | |||
| 577 | ✗ | void Layout::apply(uint32_t unitLength, Position const& pose) | |
| 578 | { | ||
| 579 | ✗ | result_t result = gate_ui_layout_apply(this, unitLength, &pose); | |
| 580 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 581 | ✗ | } | |
| 582 | |||
| 583 | |||
| 584 | ✗ | IControlManager::~IControlManager() noexcept | |
| 585 | { | ||
| 586 | ✗ | } | |
| 587 | |||
| 588 | ✗ | HostControlManager::HostControlManager() | |
| 589 | { | ||
| 590 | |||
| 591 | ✗ | } | |
| 592 | |||
| 593 | ✗ | HostControlManager::~HostControlManager() noexcept | |
| 594 | { | ||
| 595 | |||
| 596 | ✗ | } | |
| 597 | |||
| 598 | ✗ | void HostControlManager::createHost(uintptr_t hostHandle) | |
| 599 | { | ||
| 600 | ✗ | if (this->uihost.empty()) | |
| 601 | { | ||
| 602 | ✗ | this->uihost.create(); | |
| 603 | ✗ | this->uihost->init(hostHandle); | |
| 604 | } | ||
| 605 | ✗ | } | |
| 606 | ✗ | void HostControlManager::cleanupControls() | |
| 607 | { | ||
| 608 | ✗ | for (Enumerator<ControlRef const> iter = this->inactiveControls.enumerate(); iter.valid(); iter.next()) | |
| 609 | { | ||
| 610 | ✗ | Control& ctrl = *iter->get(); | |
| 611 | ✗ | if (ctrl.isCreated()) | |
| 612 | { | ||
| 613 | ✗ | ctrl.destroy(); | |
| 614 | } | ||
| 615 | } | ||
| 616 | ✗ | this->inactiveControls.clear(); | |
| 617 | ✗ | } | |
| 618 | |||
| 619 | ✗ | void HostControlManager::destroyHost() | |
| 620 | { | ||
| 621 | ✗ | this->inactiveControls.addItems(this->activeControls.begin(), this->activeControls.end()); | |
| 622 | ✗ | this->activeControls.clear(); | |
| 623 | ✗ | this->cleanupControls(); | |
| 624 | |||
| 625 | ✗ | this->uihost.reset(); | |
| 626 | ✗ | } | |
| 627 | |||
| 628 | |||
| 629 | ✗ | Host& HostControlManager::getHost() | |
| 630 | { | ||
| 631 | ✗ | if (!this->uihost) | |
| 632 | { | ||
| 633 | ✗ | GATEXX_RAISE_EXCEPTION(results::NullPointer, "UI host not initialized", 0); | |
| 634 | } | ||
| 635 | ✗ | return *this->uihost; | |
| 636 | } | ||
| 637 | |||
| 638 | ✗ | void HostControlManager::add(ControlRef ctrl) | |
| 639 | { | ||
| 640 | ✗ | this->activeControls.add(ctrl); | |
| 641 | ✗ | } | |
| 642 | |||
| 643 | ✗ | void HostControlManager::remove(Control& ctrl) | |
| 644 | { | ||
| 645 | ✗ | ControlList::iterator it = this->activeControls.begin(); | |
| 646 | ✗ | ControlList::iterator itend = this->activeControls.end(); | |
| 647 | |||
| 648 | ✗ | for (; it != itend; ++it) | |
| 649 | { | ||
| 650 | ✗ | if (it->get() == &ctrl) | |
| 651 | { | ||
| 652 | ✗ | ControlRef selectedCtrl = *it; | |
| 653 | ✗ | if (selectedCtrl) | |
| 654 | { | ||
| 655 | ✗ | if (selectedCtrl->isCreated()) | |
| 656 | { | ||
| 657 | ✗ | selectedCtrl->destroy(); | |
| 658 | } | ||
| 659 | ✗ | this->inactiveControls.add(selectedCtrl); | |
| 660 | ✗ | this->activeControls.remove(it); | |
| 661 | } | ||
| 662 | } | ||
| 663 | } | ||
| 664 | ✗ | if (this->activeControls.empty() && this->uihost) | |
| 665 | { | ||
| 666 | ✗ | this->uihost->quit(); | |
| 667 | } | ||
| 668 | ✗ | } | |
| 669 | |||
| 670 | } // end of namespace ui | ||
| 671 | } // end of namespace gate | ||
| 672 |