GCC Code Coverage Report


Directory: src/gate/
File: src/gate/ui/cxx_textboxes.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 0 83 0.0%
Functions: 0 15 0.0%
Branches: 0 58 0.0%

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/textboxes.hpp"
30
31 namespace gate
32 {
33 namespace ui
34 {
35
36 uint32_t const Textbox::Flag_Multiline = GATE_UI_FLAG_TEXTBOX_MULTILINE;
37 uint32_t const Textbox::Flag_ReturnKey = GATE_UI_FLAG_TEXTBOX_RETURNKEY;
38 uint32_t const Textbox::Flag_ReadOnly = GATE_UI_FLAG_TEXTBOX_READONLY;
39 uint32_t const Textbox::Flag_HScroll = GATE_UI_FLAG_TEXTBOX_HSCROLL;
40 uint32_t const Textbox::Flag_VScroll = GATE_UI_FLAG_TEXTBOX_VSCROLL;
41
42
43
44
45 uint32_t const Textbox::Find_Default = GATE_UI_TEXTBOX_FIND_DEFAULT;
46 uint32_t const Textbox::Find_Backwards = GATE_UI_TEXTBOX_FIND_BACKWARDS;
47 uint32_t const Textbox::Find_CaseInsensitive = GATE_UI_TEXTBOX_FIND_CASEINSENSITIVE;
48
49
50
51 void Textbox::on_char(gate_ui_ctrl_t* sender, char_32_t* chr)
52 {
53 Textbox* txt = static_cast<Textbox*>(gate_ui_ctrl_get_userparam(sender));
54 if (txt != NULL)
55 {
56 try
57 {
58 txt->onChar(*chr);
59 }
60 catch (...) {}
61 }
62 }
63
64 Textbox::Textbox()
65 : Control(&impl.ctrl)
66 {
67 Mem::clear(&this->impl, sizeof(this->impl));
68 gate_ui_ctrl_init(&this->impl.ctrl);
69 }
70 Textbox::~Textbox() noexcept
71 {
72 if (this->isCreated())
73 {
74 this->destroy();
75 Mem::clear(&this->impl, sizeof(this->impl));
76 }
77 }
78 void Textbox::create(ControlContainer& parent, Position const& pose, String const& caption, uint32_t flags)
79 {
80 this->failIfCreated("Textbox::create");
81
82 result_t result = gate_ui_textbox_create(&this->impl, *parent, &pose, caption.c_impl(), flags, this);
83 GATEXX_CHECK_ERROR(result);
84 this->impl.on_char = &Textbox::on_char;
85
86 this->attachNativeControl(&this->impl.ctrl);
87
88 }
89
90 uint32_t Textbox::getLineCount()
91 {
92 this->failIfNotCreated("Textbox::getLineCount");
93
94 uint32_t cnt = 0;
95 result_t result = gate_ui_textbox_get_line(&this->impl, NULL, &cnt);
96 GATEXX_CHECK_EXCEPTION(result);
97 return cnt;
98 }
99 uint32_t Textbox::getCurrentLine()
100 {
101 this->failIfNotCreated("Textbox::getCurrentLine");
102
103 uint32_t line = 0;
104 result_t result = gate_ui_textbox_get_line(&this->impl, &line, NULL);
105 GATEXX_CHECK_EXCEPTION(result);
106 return line;
107 }
108 uint32_t Textbox::getCurrentColumn()
109 {
110 this->failIfNotCreated("Textbox::getCurrentColumn");
111 uint32_t col = 0;
112 result_t result = gate_ui_textbox_get_column(&this->impl, &col);
113 GATEXX_CHECK_EXCEPTION(result);
114 return col;
115
116 }
117 void Textbox::getSelection(uint32_t& selStart, uint32_t& selEnd)
118 {
119 this->failIfNotCreated("Textbox::getSelection");
120
121 result_t result = gate_ui_textbox_get_selection(&this->impl, &selStart, &selEnd, NULL);
122 GATEXX_CHECK_EXCEPTION(result);
123 }
124 String Textbox::getSelectionText()
125 {
126 this->failIfNotCreated("Textbox::getSelectionText");
127
128 gate_string_t text;
129 result_t result = gate_ui_textbox_get_selection(&this->impl, NULL, NULL, &text);
130 GATEXX_CHECK_EXCEPTION(result);
131 return String::createFrom(text);
132 }
133 void Textbox::setSelection(uint32_t selStart, uint32_t selEnd)
134 {
135 this->failIfNotCreated("Textbox::setSelection");
136
137 result_t result = gate_ui_textbox_set_selection(&this->impl, selStart, selEnd, false);
138 GATEXX_CHECK_EXCEPTION(result);
139 }
140 void Textbox::replaceSelection(String const& str)
141 {
142 this->failIfNotCreated("Textbox::replaceSelection");
143
144 result_t result = gate_ui_textbox_replace_selection(&this->impl, str.c_impl());
145 GATEXX_CHECK_EXCEPTION(result);
146 }
147 void Textbox::undo()
148 {
149 this->failIfNotCreated("Textbox::undo");
150
151 result_t result = gate_ui_textbox_undo(&this->impl);
152 GATEXX_CHECK_EXCEPTION(result);
153 }
154 void Textbox::setFont(Font const& fnt)
155 {
156 this->failIfNotCreated("Textbox::setFont");
157 result_t result = gate_ui_textbox_set_font(&this->impl, &fnt);
158 GATEXX_CHECK_EXCEPTION(result);
159 }
160
161
162 void Textbox::onChar(char_32_t& chr)
163 {
164 KeyCharArg arg(chr);
165 this->KeyEvent(this, &arg);
166 chr = arg.Char;
167 }
168
169 bool_t Textbox::findNext(String const& token, uint32_t findFlags)
170 {
171 this->failIfNotCreated("Textbox::findNext");
172 gate_result_t result = gate_ui_textbox_find_next(&this->impl, token.c_impl(), findFlags);
173 if (result == GATE_RESULT_NOMATCH)
174 {
175 return false;
176 }
177 GATEXX_CHECK_EXCEPTION(result);
178 return true;
179 }
180
181 } // end of namespace ui
182 } // end of namespace gate
183
184