| 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/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 | ✗ | void Host::init(uintptr_t appHandle) | |
| 79 | { | ||
| 80 | ✗ | gate_result_t result = gate_ui_host_init(&this->impl, appHandle, this); | |
| 81 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 82 | ✗ | this->ptr = &this->impl; | |
| 83 | ✗ | } | |
| 84 | |||
| 85 | |||
| 86 | ✗ | Host::Host(uintptr_t appHandle) | |
| 87 | ✗ | : ptr(NULL) | |
| 88 | { | ||
| 89 | ✗ | this->init(appHandle); | |
| 90 | ✗ | } | |
| 91 | |||
| 92 | ✗ | Host::~Host() noexcept | |
| 93 | { | ||
| 94 | ✗ | if (this->ptr) | |
| 95 | { | ||
| 96 | ✗ | gate_ui_host_uninit(this->ptr); | |
| 97 | } | ||
| 98 | ✗ | } | |
| 99 | |||
| 100 | ✗ | Host& Host::getHost(Control& ctrl) | |
| 101 | { | ||
| 102 | ✗ | gate_ui_ctrl_t* ptr_ctrl = ctrl.c_impl(); | |
| 103 | ✗ | if (!ptr_ctrl) | |
| 104 | { | ||
| 105 | ✗ | GATEXX_RAISE_ERROR(results::NullPointer); | |
| 106 | } | ||
| 107 | ✗ | gate_ui_host_t* ptr_host = gate_ui_ctrl_get_host(ptr_ctrl); | |
| 108 | ✗ | if (!ptr_host) | |
| 109 | { | ||
| 110 | ✗ | GATEXX_RAISE_ERROR(results::NullPointer); | |
| 111 | } | ||
| 112 | ✗ | return Host::getHost(*ptr_host); | |
| 113 | } | ||
| 114 | |||
| 115 | ✗ | Host& Host::getHost(gate_ui_host_t& hostImpl) | |
| 116 | { | ||
| 117 | ✗ | void* obj_ptr = gate_ui_host_get_userparam(&hostImpl); | |
| 118 | ✗ | if (!obj_ptr) | |
| 119 | { | ||
| 120 | ✗ | GATEXX_RAISE_ERROR(results::NullPointer); | |
| 121 | } | ||
| 122 | ✗ | return *static_cast<Host*>(obj_ptr); | |
| 123 | } | ||
| 124 | |||
| 125 | |||
| 126 | ✗ | void Host::run() | |
| 127 | { | ||
| 128 | ✗ | gate_ui_host_run(this->c_impl()); | |
| 129 | ✗ | } | |
| 130 | |||
| 131 | ✗ | void Host::quit() | |
| 132 | { | ||
| 133 | ✗ | gate_ui_host_quit(this->c_impl()); | |
| 134 | ✗ | } | |
| 135 | |||
| 136 | ✗ | uint32_t Host::getLineHeight() | |
| 137 | { | ||
| 138 | ✗ | return gate_ui_host_default_line_height(this->c_impl()); | |
| 139 | } | ||
| 140 | ✗ | uint32_t Host::getControlHeight(uint32_t lines) | |
| 141 | { | ||
| 142 | ✗ | return gate_ui_host_default_control_height(this->c_impl(), lines); | |
| 143 | } | ||
| 144 | |||
| 145 | ✗ | int32_t Host::getUnitLength(real32_t units) | |
| 146 | { | ||
| 147 | ✗ | real32_t controlHeight = static_cast<real32_t>(this->getControlHeight()); | |
| 148 | ✗ | 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 | ✗ | Font Host::getDefaultFont(uint32_t fonttype) | |
| 161 | { | ||
| 162 | ✗ | result_t res = GATE_RESULT_OK; | |
| 163 | ✗ | Font fnt; | |
| 164 | ✗ | gate_ui_font_t* ptrfnt = &fnt; | |
| 165 | ✗ | res = gate_ui_host_default_font(this->c_impl(), fonttype, ptrfnt); | |
| 166 | ✗ | GATEXX_CHECK_ERROR(res); | |
| 167 | ✗ | return fnt; | |
| 168 | } | ||
| 169 | ✗ | int32_t Host::getPixelsOfPoints(real32_t points) | |
| 170 | { | ||
| 171 | ✗ | return gate_ui_host_get_pixels_in_points(this->c_impl(), points); | |
| 172 | } | ||
| 173 | ✗ | real32_t Host::getPointsOfPixels(int32_t pixels) | |
| 174 | { | ||
| 175 | ✗ | return gate_ui_host_get_points_in_pixels(this->c_impl(), pixels); | |
| 176 | } | ||
| 177 | |||
| 178 | |||
| 179 | ✗ | static bool_t 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 | ✗ | gate_ui_host_t* Host::operator*() | |
| 237 | { | ||
| 238 | ✗ | return this->ptr; | |
| 239 | } | ||
| 240 | ✗ | gate_ui_host_t const* Host::operator*() const | |
| 241 | { | ||
| 242 | ✗ | return this->ptr; | |
| 243 | } | ||
| 244 | ✗ | gate_ui_host_t* Host::c_impl() | |
| 245 | { | ||
| 246 | ✗ | return this->ptr; | |
| 247 | } | ||
| 248 | ✗ | gate_ui_host_t const* Host::c_impl() const | |
| 249 | { | ||
| 250 | ✗ | return this->ptr; | |
| 251 | } | ||
| 252 | |||
| 253 | |||
| 254 | |||
| 255 | |||
| 256 | ////////////////////////////// | ||
| 257 | // // | ||
| 258 | // Control implementation // | ||
| 259 | // // | ||
| 260 | ////////////////////////////// | ||
| 261 | |||
| 262 | uint32_t const Control::Flag_Enabled = GATE_UI_FLAG_ENABLED; | ||
| 263 | uint32_t const Control::Flag_Visible = GATE_UI_FLAG_VISIBLE; | ||
| 264 | uint32_t const Control::Flag_Resizable = GATE_UI_FLAG_RESIZABLE; | ||
| 265 | |||
| 266 | |||
| 267 | ✗ | Control::~Control() noexcept | |
| 268 | { | ||
| 269 | ✗ | this->destroy(); | |
| 270 | ✗ | } | |
| 271 | |||
| 272 | ✗ | gate_ui_ctrl_t* Control::operator*() const | |
| 273 | { | ||
| 274 | ✗ | return this->ctrl; | |
| 275 | } | ||
| 276 | |||
| 277 | |||
| 278 | ✗ | void Control::destroy() noexcept | |
| 279 | { | ||
| 280 | ✗ | if (this->ctrl != NULL) | |
| 281 | { | ||
| 282 | ✗ | gate_ui_ctrl_destroy(this->ctrl); | |
| 283 | ✗ | this->ctrl = NULL; | |
| 284 | } | ||
| 285 | ✗ | } | |
| 286 | |||
| 287 | ✗ | bool Control::isCreated() const noexcept | |
| 288 | { | ||
| 289 | ✗ | if (this->ctrl == NULL) | |
| 290 | { | ||
| 291 | ✗ | return false; | |
| 292 | } | ||
| 293 | else | ||
| 294 | { | ||
| 295 | ✗ | return gate_ui_ctrl_is_created(this->ctrl); | |
| 296 | } | ||
| 297 | } | ||
| 298 | ✗ | bool Control::isEnabled() const | |
| 299 | { | ||
| 300 | ✗ | return gate_ui_ctrl_is_enabled(this->ctrl); | |
| 301 | } | ||
| 302 | ✗ | bool Control::isFocused() const | |
| 303 | { | ||
| 304 | ✗ | return gate_ui_ctrl_is_focused(this->ctrl); | |
| 305 | } | ||
| 306 | ✗ | bool Control::isVisible() const | |
| 307 | { | ||
| 308 | ✗ | return gate_ui_ctrl_is_visible(this->ctrl); | |
| 309 | } | ||
| 310 | ✗ | Position Control::getPosition() const | |
| 311 | { | ||
| 312 | ✗ | Position pos; | |
| 313 | ✗ | result_t result = gate_ui_ctrl_get_position(this->ctrl, &pos); | |
| 314 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 315 | ✗ | return pos; | |
| 316 | } | ||
| 317 | ✗ | Size Control::getSize() const | |
| 318 | { | ||
| 319 | ✗ | Size sz; | |
| 320 | ✗ | result_t result = gate_ui_ctrl_get_size(this->ctrl, &sz); | |
| 321 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 322 | ✗ | return sz; | |
| 323 | } | ||
| 324 | ✗ | uint32_t Control::getTextLength() const | |
| 325 | { | ||
| 326 | ✗ | uint32_t ret = 0; | |
| 327 | ✗ | result_t result = gate_ui_ctrl_get_text_length(this->ctrl, &ret); | |
| 328 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 329 | ✗ | return ret; | |
| 330 | } | ||
| 331 | |||
| 332 | ✗ | String Control::getText() const | |
| 333 | { | ||
| 334 | gate_string_t str; | ||
| 335 | ✗ | result_t result = gate_ui_ctrl_get_text(this->ctrl, &str); | |
| 336 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 337 | ✗ | return String::createFrom(str); | |
| 338 | } | ||
| 339 | ✗ | int32_t Control::getState() const | |
| 340 | { | ||
| 341 | ✗ | int32_t ret = 0; | |
| 342 | ✗ | result_t result = gate_ui_ctrl_get_state(this->ctrl, &ret); | |
| 343 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 344 | ✗ | return ret; | |
| 345 | } | ||
| 346 | |||
| 347 | ✗ | void Control::setEnabled(bool enabled) | |
| 348 | { | ||
| 349 | ✗ | result_t result = gate_ui_ctrl_set_enabled(this->ctrl, enabled); | |
| 350 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 351 | ✗ | } | |
| 352 | ✗ | void Control::setVisible(bool visible) | |
| 353 | { | ||
| 354 | ✗ | result_t result = gate_ui_ctrl_set_visible(this->ctrl, visible); | |
| 355 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 356 | ✗ | } | |
| 357 | ✗ | void Control::setPosition(Point const* position, Size const* size) | |
| 358 | { | ||
| 359 | ✗ | result_t result = gate_ui_ctrl_set_position(this->ctrl, position, size); | |
| 360 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 361 | ✗ | } | |
| 362 | ✗ | void Control::setPosition(Position const& pos) | |
| 363 | { | ||
| 364 | ✗ | Point pnt(pos.pos); | |
| 365 | ✗ | Size sz(pos.size); | |
| 366 | ✗ | this->setPosition(&pnt, &sz); | |
| 367 | ✗ | } | |
| 368 | ✗ | void Control::setFocus() | |
| 369 | { | ||
| 370 | ✗ | result_t result = gate_ui_ctrl_set_focus(this->ctrl); | |
| 371 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 372 | ✗ | } | |
| 373 | |||
| 374 | |||
| 375 | |||
| 376 | ✗ | void Control::setText(String const& text) | |
| 377 | { | ||
| 378 | ✗ | result_t result = gate_ui_ctrl_set_text(this->ctrl, text.c_impl()); | |
| 379 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 380 | ✗ | } | |
| 381 | ✗ | void Control::setState(int32_t state) | |
| 382 | { | ||
| 383 | ✗ | result_t result = gate_ui_ctrl_set_state(this->ctrl, state); | |
| 384 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 385 | ✗ | } | |
| 386 | |||
| 387 | ✗ | Control::Control(gate_ui_ctrl_t* ctrlimpl) | |
| 388 | ✗ | : ctrl_impl(ctrlimpl), ctrl(NULL) | |
| 389 | { | ||
| 390 | |||
| 391 | ✗ | } | |
| 392 | ✗ | gate_ui_ctrl_t* Control::c_impl() const | |
| 393 | { | ||
| 394 | ✗ | return this->ctrl_impl; | |
| 395 | } | ||
| 396 | |||
| 397 | ✗ | void Control::attachNativeControl(gate_ui_ctrl_t* ctl) | |
| 398 | { | ||
| 399 | ✗ | this->ctrl = ctl; | |
| 400 | ✗ | } | |
| 401 | |||
| 402 | ✗ | void Control::failIfCreated(char const* sourceFunction) | |
| 403 | { | ||
| 404 | ✗ | if (this->isCreated()) | |
| 405 | { | ||
| 406 | ✗ | raiseError(results::InvalidState, | |
| 407 | (sourceFunction == NULL) ? "Control::failIfCreated" : sourceFunction); | ||
| 408 | } | ||
| 409 | ✗ | } | |
| 410 | ✗ | void Control::failIfNotCreated(char const* sourceFunction) | |
| 411 | { | ||
| 412 | ✗ | if (!this->isCreated()) | |
| 413 | { | ||
| 414 | ✗ | raiseError(results::InvalidState, | |
| 415 | (sourceFunction == NULL) ? "Control::failIfNotCreated" : sourceFunction); | ||
| 416 | } | ||
| 417 | ✗ | } | |
| 418 | |||
| 419 | |||
| 420 | |||
| 421 | |||
| 422 | /////////////////////////////////////// | ||
| 423 | // // | ||
| 424 | // ControlContainer implementation // | ||
| 425 | // // | ||
| 426 | /////////////////////////////////////// | ||
| 427 | |||
| 428 | ✗ | ControlContainer::ControlContainer(gate_ui_ctrl_t* ctrlimpl) | |
| 429 | ✗ | : Control(ctrlimpl) | |
| 430 | { | ||
| 431 | |||
| 432 | ✗ | } | |
| 433 | ✗ | ControlContainer::~ControlContainer() noexcept | |
| 434 | { | ||
| 435 | ✗ | } | |
| 436 | |||
| 437 | ✗ | Array<Control*> ControlContainer::getChildren() const | |
| 438 | { | ||
| 439 | ✗ | Array<Control*> ret; | |
| 440 | //TODO | ||
| 441 | ✗ | return ret; | |
| 442 | } | ||
| 443 | |||
| 444 | ✗ | void ControlContainer::setLayout(Layout const* layout) | |
| 445 | { | ||
| 446 | ✗ | } | |
| 447 | |||
| 448 | |||
| 449 | |||
| 450 | ///////////////////////////// | ||
| 451 | // Layout implementation // | ||
| 452 | ///////////////////////////// | ||
| 453 | |||
| 454 | enumint_t const Layout::Type_Auto = GATE_UI_LAYOUT_TYPE_AUTO; | ||
| 455 | enumint_t const Layout::Type_Pixel = GATE_UI_LAYOUT_TYPE_PIXEL; | ||
| 456 | enumint_t const Layout::Type_Percent = GATE_UI_LAYOUT_TYPE_PERCENT; | ||
| 457 | enumint_t const Layout::Type_UnitScale = GATE_UI_LAYOUT_TYPE_UNITSCALE; | ||
| 458 | |||
| 459 | ✗ | Layout::Layout() | |
| 460 | { | ||
| 461 | ✗ | result_t result = gate_ui_layout_create(this); | |
| 462 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 463 | ✗ | } | |
| 464 | ✗ | Layout::~Layout() | |
| 465 | { | ||
| 466 | ✗ | gate_ui_layout_destroy(this); | |
| 467 | ✗ | } | |
| 468 | |||
| 469 | ✗ | void Layout::clear() | |
| 470 | { | ||
| 471 | ✗ | gate_ui_layout_clear(this); | |
| 472 | ✗ | } | |
| 473 | |||
| 474 | ✗ | uint32_t Layout::addColumn(enumint_t type, real32_t value) | |
| 475 | { | ||
| 476 | ✗ | gate_uint32_t colindex = gate_ui_layout_get_columns(this); | |
| 477 | ✗ | result_t result = gate_ui_layout_add_column(this, type, value); | |
| 478 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 479 | ✗ | return colindex; | |
| 480 | } | ||
| 481 | ✗ | uint32_t Layout::addRow(enumint_t type, real32_t value) | |
| 482 | { | ||
| 483 | ✗ | gate_uint32_t rowindex = gate_ui_layout_get_rows(this); | |
| 484 | ✗ | result_t result = gate_ui_layout_add_row(this, type, value); | |
| 485 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 486 | ✗ | return rowindex; | |
| 487 | } | ||
| 488 | |||
| 489 | ✗ | void Layout::setBorder(uint32_t borderWidth) | |
| 490 | { | ||
| 491 | ✗ | this->border = borderWidth; | |
| 492 | ✗ | } | |
| 493 | ✗ | void Layout::setColumnSpace(uint32_t colSpace) | |
| 494 | { | ||
| 495 | ✗ | this->colspace = colSpace; | |
| 496 | ✗ | } | |
| 497 | ✗ | void Layout::setRowSpace(uint32_t rowSpace) | |
| 498 | { | ||
| 499 | ✗ | this->rowspace = rowSpace; | |
| 500 | ✗ | } | |
| 501 | |||
| 502 | |||
| 503 | ✗ | void Layout::setControl(Control const& ctrl, uint32_t row, uint32_t col, uint32_t rowspan, uint32_t colspan) | |
| 504 | { | ||
| 505 | ✗ | result_t result = gate_ui_layout_set_control(this, ctrl.c_impl(), row, col, rowspan, colspan); | |
| 506 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 507 | ✗ | } | |
| 508 | |||
| 509 | ✗ | void Layout::apply(uint32_t unitLength, Position const& pose) | |
| 510 | { | ||
| 511 | ✗ | result_t result = gate_ui_layout_apply(this, unitLength, &pose); | |
| 512 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 513 | ✗ | } | |
| 514 | |||
| 515 | |||
| 516 | ✗ | IControlManager::~IControlManager() noexcept | |
| 517 | { | ||
| 518 | ✗ | } | |
| 519 | |||
| 520 | ✗ | HostControlManager::HostControlManager() | |
| 521 | { | ||
| 522 | |||
| 523 | ✗ | } | |
| 524 | |||
| 525 | ✗ | HostControlManager::~HostControlManager() noexcept | |
| 526 | { | ||
| 527 | |||
| 528 | ✗ | } | |
| 529 | |||
| 530 | ✗ | void HostControlManager::createHost(uintptr_t hostHandle) | |
| 531 | { | ||
| 532 | ✗ | if (this->uihost.empty()) | |
| 533 | { | ||
| 534 | ✗ | this->uihost.create(); | |
| 535 | ✗ | this->uihost->init(hostHandle); | |
| 536 | } | ||
| 537 | ✗ | } | |
| 538 | ✗ | void HostControlManager::cleanupControls() | |
| 539 | { | ||
| 540 | ✗ | for (Enumerator<ControlRef const> iter = this->inactiveControls.enumerate(); iter.valid(); iter.next()) | |
| 541 | { | ||
| 542 | ✗ | Control& ctrl = *iter->get(); | |
| 543 | ✗ | if (ctrl.isCreated()) | |
| 544 | { | ||
| 545 | ✗ | ctrl.destroy(); | |
| 546 | } | ||
| 547 | } | ||
| 548 | ✗ | this->inactiveControls.clear(); | |
| 549 | ✗ | } | |
| 550 | |||
| 551 | ✗ | void HostControlManager::destroyHost() | |
| 552 | { | ||
| 553 | ✗ | this->inactiveControls.addItems(this->activeControls.begin(), this->activeControls.end()); | |
| 554 | ✗ | this->activeControls.clear(); | |
| 555 | ✗ | this->cleanupControls(); | |
| 556 | |||
| 557 | ✗ | this->uihost.reset(); | |
| 558 | ✗ | } | |
| 559 | |||
| 560 | |||
| 561 | ✗ | Host& HostControlManager::getHost() | |
| 562 | { | ||
| 563 | ✗ | if (!this->uihost) | |
| 564 | { | ||
| 565 | ✗ | GATEXX_RAISE_EXCEPTION(results::NullPointer, "UI host not initialized", 0); | |
| 566 | } | ||
| 567 | ✗ | return *this->uihost; | |
| 568 | } | ||
| 569 | |||
| 570 | ✗ | void HostControlManager::add(ControlRef ctrl) | |
| 571 | { | ||
| 572 | ✗ | this->activeControls.add(ctrl); | |
| 573 | ✗ | } | |
| 574 | |||
| 575 | ✗ | void HostControlManager::remove(Control& ctrl) | |
| 576 | { | ||
| 577 | ✗ | ControlList::iterator it = this->activeControls.begin(); | |
| 578 | ✗ | ControlList::iterator itend = this->activeControls.end(); | |
| 579 | |||
| 580 | ✗ | for (; it != itend; ++it) | |
| 581 | { | ||
| 582 | ✗ | if (it->get() == &ctrl) | |
| 583 | { | ||
| 584 | ✗ | ControlRef selectedCtrl = *it; | |
| 585 | ✗ | if (selectedCtrl) | |
| 586 | { | ||
| 587 | ✗ | if (selectedCtrl->isCreated()) | |
| 588 | { | ||
| 589 | ✗ | selectedCtrl->destroy(); | |
| 590 | } | ||
| 591 | ✗ | this->inactiveControls.add(selectedCtrl); | |
| 592 | ✗ | this->activeControls.remove(it); | |
| 593 | } | ||
| 594 | } | ||
| 595 | } | ||
| 596 | ✗ | if (this->activeControls.empty() && this->uihost) | |
| 597 | { | ||
| 598 | ✗ | this->uihost->quit(); | |
| 599 | } | ||
| 600 | ✗ | } | |
| 601 | |||
| 602 | } // end of namespace ui | ||
| 603 | } // end of namespace gate | ||
| 604 |