| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/ui/UIEdit.cpp $ |
| 21 | * $Revision: 33 $ |
| 22 | * $Date: 10/21/99 3:30p $ |
| 23 | * $Author: Kevin $ |
| 24 | * |
| 25 | * Edit control |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/ui/UIEdit.cpp $ |
| 28 | * |
| 29 | * 33 10/21/99 3:30p Kevin |
| 30 | * mac merge |
| 31 | * |
| 32 | * 32 5/17/99 5:19p Samir |
| 33 | * added ability for edit box to autoselect when hitting the max number of |
| 34 | * characters typable. |
| 35 | * |
| 36 | * 31 5/06/99 1:24a Samir |
| 37 | * upped editbox maxlength to 512 |
| 38 | * |
| 39 | * 30 5/06/99 1:20a Samir |
| 40 | * allow editboxes with max buffer length of 280 |
| 41 | * |
| 42 | * 29 4/28/99 1:54a Samir |
| 43 | * visual tweaks to text |
| 44 | * |
| 45 | * 28 4/21/99 12:42p Samir |
| 46 | * change some communication betwen UIEdit and child classes. |
| 47 | * |
| 48 | * 27 4/20/99 11:46a Samir |
| 49 | * numerous ui 'feel' fixes. |
| 50 | * |
| 51 | * 26 4/14/99 1:52a Jeff |
| 52 | * fixed case mismatched #includes |
| 53 | * |
| 54 | * 25 2/28/99 3:25a Samir |
| 55 | * added flag to input only numbers. |
| 56 | * |
| 57 | * 24 2/21/99 6:36p Samir |
| 58 | * focusing changes and key input changes to ui., |
| 59 | * |
| 60 | * 23 10/19/98 12:18p Samir |
| 61 | * made tabbing between edit controls possible. |
| 62 | * |
| 63 | * 22 10/17/98 11:26a Samir |
| 64 | * fixed some edit box scrolling issues. |
| 65 | * |
| 66 | * 21 10/13/98 8:23p Samir |
| 67 | * communication between gadget and window and edit system to work |
| 68 | * together. |
| 69 | * |
| 70 | * 20 10/06/98 7:30p Samir |
| 71 | * activate listbox when created. |
| 72 | * |
| 73 | * 19 9/30/98 4:33p Samir |
| 74 | * disabled gadgets display dim text. |
| 75 | * |
| 76 | * 18 9/24/98 1:13p Samir |
| 77 | * edit box a bit better. |
| 78 | * |
| 79 | * 17 9/14/98 11:22a Samir |
| 80 | * enhanced editboxes |
| 81 | * |
| 82 | * 16 8/26/98 12:25p Samir |
| 83 | * fixed the whole editbox, keyboard access mess. |
| 84 | * |
| 85 | * 15 8/25/98 5:36p Samir |
| 86 | * added call to lock key focus in Activate too. |
| 87 | * |
| 88 | * 14 8/25/98 5:27p Samir |
| 89 | * new focusing rules for keyboard. |
| 90 | * |
| 91 | * 13 6/22/98 7:31p Samir |
| 92 | * added UIEdit::Activate, which activates an edit box manually. |
| 93 | * |
| 94 | * 12 6/22/98 3:46p Samir |
| 95 | * fixed bug in UIEdit password system. |
| 96 | * |
| 97 | * 11 6/22/98 2:52p Samir |
| 98 | * call Onselect for UIEdit boxes if edit is pressed. |
| 99 | * |
| 100 | * 10 6/22/98 2:15p Samir |
| 101 | * implemented border flag. |
| 102 | * |
| 103 | * 9 6/15/98 5:27p Kevin |
| 104 | * Fixed bug in UIEdit::GetText where m_TextBuf was NULL |
| 105 | * |
| 106 | * 8 5/25/98 8:17p Samir |
| 107 | * fixed some UI bugs with edit boxes. |
| 108 | * |
| 109 | * 7 4/13/98 7:02p Samir |
| 110 | * made some things protected. |
| 111 | * |
| 112 | * 6 3/10/98 11:03a Jeff |
| 113 | * changed strcpy to strncpy in GetText |
| 114 | * |
| 115 | * 5 1/30/98 7:05p Samir |
| 116 | * Each gadget now has their own coordinate system. |
| 117 | * |
| 118 | * 4 1/18/98 4:23p Samir |
| 119 | * Moved object destruction code to a virtual OnDestroy function for |
| 120 | * gadgets. Must destroy window too. |
| 121 | * |
| 122 | * 3 1/13/98 4:27p Samir |
| 123 | * Keyboard timing delay stored UIGadget. Moved from UIEdit. |
| 124 | * |
| 125 | * 2 1/05/98 4:36p Samir |
| 126 | * Moved centering and fittext control flags to UIGadget class. |
| 127 | * |
| 128 | * 1 1/02/98 12:49p Samir |
| 129 | * Initial revision. |
| 130 | * |
| 131 | * |
| 132 | * $NoKeywords: $ |
| 133 | */ |
| 134 | |
| 135 | #include <cstdio> |
| 136 | #include <cstring> |
| 137 | #include <cstdlib> |
| 138 | |
| 139 | #include "UIlib.h"cxx . . $ `<file>/ui/UIlib.h`/ |
| 140 | #include "grtext.h"cxx . . $ `<file>/grtext/grtext.h`/ |
| 141 | #include "Macros.h"cxx . . $ `<file>/lib/Macros.h`/ |
| 142 | #include "mem.h"cxx . . $ `<file>/mem/mem.h`/ |
| 143 | |
| 144 | |
| 145 | static UIEditcxx . . $ UIEdit# *UI_current_editboxcxx . . $ UI_current_editbox. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 146 | |
| 147 | // ---------------------------------------------------------------------------- |
| 148 | // UIEdit |
| 149 | // A single line edit control. |
| 150 | |
| 151 | UIEditcxx . . $ UIEdit#::UIEditcxx . . $ UIEdit#UIEdit(49f6e7a06ebc5aa8).() { |
| 152 | m_TextBufcxx . . $ UIEdit#m_TextBuf. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 153 | m_BufSizecxx . . $ UIEdit#m_BufSize. = 0; |
| 154 | m_FontHandlecxx . . $ UIEdit#m_FontHandle. = -1; |
| 155 | } |
| 156 | |
| 157 | UIEditcxx . . $ UIEdit#::~cxx . . $ UIEdit#`~UIEdit`(ced63f7c635d850d).UIEditcxx . . $ UIEdit#() {} |
| 158 | |
| 159 | void UIEditcxx . . $ UIEdit#::Createcxx . . $ UIEdit#Create(43707b8add2f137d).(UIWindowcxx . . $ UIWindow# *parent, int id, int x, int y, int w, int h, int flags) { |
| 160 | m_BufSizecxx . . $ UIEdit#m_BufSize. = 32; |
| 161 | m_TextBufcxx . . $ UIEdit#m_TextBuf. = (char *)mem_malloccxx . . $ `mem/mem.h:79:9`!(m_BufSize + 1); |
| 162 | m_TextBufcxx . . $ UIEdit#m_TextBuf.[0] = 0; |
| 163 | m_CursorPosXcxx . . $ UIEdit#m_CursorPosX. = 0; |
| 164 | m_Colorcxx . . $ UIEdit#m_Color. = GR_WHITEcxx . . $ GR_WHITE.; |
| 165 | m_Activecxx . . $ UIEdit#m_Active. = false; |
| 166 | m_StartPoscxx . . $ UIEdit#m_StartPos. = -1; |
| 167 | m_CurPoscxx . . $ UIEdit#m_CurPos. = 0; |
| 168 | UIGadgetcxx . . $ UIGadget#::Createcxx . . $ UIGadget#Create(43707b8add2f137d).(parent, id, x, y, w, h, flags); |
| 169 | SetTextBoundscxx . . $ UIEdit#SetTextBounds(b1146eedae1e1d0b).(2, m_Wcxx . . $ UIObject#m_W. - 2, 0); |
| 170 | m_ScrollThreshcxx . . $ UIEdit#m_ScrollThresh. = 0; |
| 171 | m_UpdateCountcxx . . $ UIEdit#m_UpdateCount. = false; |
| 172 | // UIEdit::Activate(); |
| 173 | } |
| 174 | |
| 175 | void UIEditcxx . . $ UIEdit#::SetTextBoundscxx . . $ UIEdit#SetTextBounds(b1146eedae1e1d0b).(int x1, int x2, int yoff) { |
| 176 | m_X1bcxx . . $ UIEdit#m_X1b. = x1; |
| 177 | m_X2bcxx . . $ UIEdit#m_X2b. = x2; |
| 178 | m_Ybcxx . . $ UIEdit#m_Yb. = yoff; |
| 179 | } |
| 180 | |
| 181 | void UIEditcxx . . $ UIEdit#::SetColorcxx . . $ UIEdit#SetColor(cb2f890c2fdad230).(ddgr_colorcxx . . $ ddgr_color# col) { m_Colorcxx . . $ UIEdit#m_Color. = col; } |
| 182 | |
| 183 | #define EDIT_BUFLEN_MAXcxx . . $ `ui/UIEdit.cpp:183:9`! 1025 // DAJ utb 512 |
| 184 | |
| 185 | // setings |
| 186 | // sets the length of the input buffer. |
| 187 | void UIEditcxx . . $ UIEdit#::SetBufferLencxx . . $ UIEdit#SetBufferLen(d4f767463ce0a6b3).(int length) { |
| 188 | char *newbuf; |
| 189 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(length < EDIT_BUFLEN_MAXcxx . . $ `ui/UIEdit.cpp:183:9`!); // there are several places in the code that depend on something like this. |
| 190 | |
| 191 | newbuf = (char *)mem_malloccxx . . $ `mem/mem.h:79:9`!(length + 1); |
| 192 | strncpy(newbuf, m_TextBufcxx . . $ UIEdit#m_TextBuf., length); |
| 193 | newbuf[length] = 0; |
| 194 | if (m_TextBufcxx . . $ UIEdit#m_TextBuf.) { |
| 195 | mem_freecxx . . $ `mem/mem.h:80:9`!(m_TextBuf); |
| 196 | } |
| 197 | m_TextBufcxx . . $ UIEdit#m_TextBuf. = newbuf; |
| 198 | m_BufSizecxx . . $ UIEdit#m_BufSize. = length; |
| 199 | m_UpdateCountcxx . . $ UIEdit#m_UpdateCount. = false; |
| 200 | } |
| 201 | |
| 202 | // sets the text buffer. |
| 203 | void UIEditcxx . . $ UIEdit#::SetTextcxx . . $ UIEdit#SetText(85c52e162fed56f9).(const char *text) { |
| 204 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(strlen(text) <= (unsigned)m_BufSize); |
| 205 | |
| 206 | if (CHECK_FLAGcxx . . $ `lib/Macros.h:63:9`!(m_Flags, UIED_NUMBERScxx . . $ `ui/ui.h:362:9`!)) { |
| 207 | int num = atoicxx . . $ atoi(f5ecf3191ed0cd93).(text); |
| 208 | sprintf(m_TextBufcxx . . $ UIEdit#m_TextBuf., "%d", num); |
| 209 | } else { |
| 210 | strcpy(m_TextBufcxx . . $ UIEdit#m_TextBuf., text); |
| 211 | } |
| 212 | |
| 213 | m_CurPoscxx . . $ UIEdit#m_CurPos. = strlen(m_TextBufcxx . . $ UIEdit#m_TextBuf.); |
| 214 | m_StartPoscxx . . $ UIEdit#m_StartPos. = -1; |
| 215 | m_UpdateCountcxx . . $ UIEdit#m_UpdateCount. = false; |
| 216 | } |
| 217 | |
| 218 | // retrieve text in edit control. |
| 219 | void UIEditcxx . . $ UIEdit#::GetTextcxx . . $ UIEdit#GetText(a07d8cccb7673f5a).(char *buffer, int len) { |
| 220 | // ASSERT(strlen(m_TextBuf) < (unsigned)len); |
| 221 | if (!m_TextBufcxx . . $ UIEdit#m_TextBuf.) { |
| 222 | buffer[0] = '\0'; |
| 223 | return; |
| 224 | } |
| 225 | strncpy(buffer, m_TextBufcxx . . $ UIEdit#m_TextBuf., len - 1); |
| 226 | buffer[len - 1] = 0; |
| 227 | } |
| 228 | |
| 229 | // sets font of control (default is window's font.) |
| 230 | void UIEditcxx . . $ UIEdit#::SetFontcxx . . $ UIEdit#SetFont(d4f767463ce0a6b3).(int font) { m_FontHandlecxx . . $ UIEdit#m_FontHandle. = font; } |
| 231 | |
| 232 | void UIEditcxx . . $ UIEdit#::Activatecxx . . $ UIEdit#Activate(49f6e7a06ebc5aa8).() { |
| 233 | if (UI_current_editboxcxx . . $ UI_current_editbox.) { |
| 234 | UI_current_editboxcxx . . $ UI_current_editbox.->Deactivatecxx . . $ UIEdit#Deactivate(49f6e7a06ebc5aa8).(); |
| 235 | } |
| 236 | |
| 237 | m_Wndcxx . . $ UIGadget#m_Wnd.->HoldHotkeyscxx . . $ UIWindow#HoldHotkeys(49f6e7a06ebc5aa8).(); |
| 238 | m_Activecxx . . $ UIEdit#m_Active. = true; |
| 239 | UI_current_editboxcxx . . $ UI_current_editbox. = this; |
| 240 | m_UpdateCountcxx . . $ UIEdit#m_UpdateCount. = false; |
| 241 | |
| 242 | // mprintf(0, "activating edit box\n"); |
| 243 | } |
| 244 | |
| 245 | // deactivates edit box (use if you know what you're doing.) |
| 246 | void UIEditcxx . . $ UIEdit#::Deactivatecxx . . $ UIEdit#Deactivate(49f6e7a06ebc5aa8).() { |
| 247 | // mprintf(0, "deactivating edit box\n"); |
| 248 | |
| 249 | m_Activecxx . . $ UIEdit#m_Active. = false; |
| 250 | UI_current_editboxcxx . . $ UI_current_editbox. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 251 | m_Wndcxx . . $ UIGadget#m_Wnd.->ResumeHotkeyscxx . . $ UIWindow#ResumeHotkeys(49f6e7a06ebc5aa8).(); |
| 252 | } |
| 253 | |
| 254 | // Overrides |
| 255 | |
| 256 | void UIEditcxx . . $ UIEdit#::OnDestroycxx . . $ UIEdit#OnDestroy(49f6e7a06ebc5aa8).() { |
| 257 | UIGadgetcxx . . $ UIGadget#::OnDestroycxx . . $ UIGadget#OnDestroy(49f6e7a06ebc5aa8).(); |
| 258 | |
| 259 | if (m_TextBufcxx . . $ UIEdit#m_TextBuf.) { |
| 260 | mem_freecxx . . $ `mem/mem.h:80:9`!(m_TextBuf); |
| 261 | } |
| 262 | |
| 263 | // if editbox is being destroyed and is the current editbox, reset to NULL. |
| 264 | if (UI_current_editboxcxx . . $ UI_current_editbox. == this) |
| 265 | UI_current_editboxcxx . . $ UI_current_editbox. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 266 | } |
| 267 | |
| 268 | // override: behavior when gadget loses input focus. |
| 269 | void UIEditcxx . . $ UIEdit#::OnLostFocuscxx . . $ UIEdit#OnLostFocus(49f6e7a06ebc5aa8).() { |
| 270 | // mprintf(0, "Edit control lost focus.\n"); |
| 271 | UIEditcxx . . $ UIEdit#::Deactivatecxx . . $ UIEdit#Deactivate(49f6e7a06ebc5aa8).(); |
| 272 | } |
| 273 | |
| 274 | // override: behavior when gadget gains input focus. |
| 275 | void UIEditcxx . . $ UIEdit#::OnGainFocuscxx . . $ UIEdit#OnGainFocus(49f6e7a06ebc5aa8).() { |
| 276 | // mprintf(0, "Edit control gained focus.\n"); |
| 277 | } |
| 278 | |
| 279 | // behavior when gadget is being drawn. |
| 280 | void UIEditcxx . . $ UIEdit#::OnDrawcxx . . $ UIEdit#OnDraw(49f6e7a06ebc5aa8).() { |
| 281 | if (m_Flagscxx . . $ UIGadget#m_Flags. & UIF_BORDERcxx . . $ `ui/ui.h:344:9`!) { |
| 282 | ui_DrawBoxcxx . . $ ui_DrawBox(fe09a4b73d8d396f).(GR_RGBcxx . . $ GR_RGB(530956271a9518a5).(128, 128, 128), m_X1bcxx . . $ UIEdit#m_X1b. - 1, 0, m_X2bcxx . . $ UIEdit#m_X2b. + 1, m_Hcxx . . $ UIObject#m_H.); |
| 283 | } |
| 284 | |
| 285 | DrawTextcxx . . $ UIEdit#DrawText(49f6e7a06ebc5aa8).(); |
| 286 | } |
| 287 | |
| 288 | void UIEditcxx . . $ UIEdit#::DrawTextcxx . . $ UIEdit#DrawText(49f6e7a06ebc5aa8).() { |
| 289 | char buffer[EDIT_BUFLEN_MAXcxx . . $ `ui/UIEdit.cpp:183:9`!]; |
| 290 | int str_w, i, cursor_w; |
| 291 | |
| 292 | if (m_FontHandlecxx . . $ UIEdit#m_FontHandle. > -1) |
| 293 | ui_DrawSetFontcxx . . $ ui_DrawSetFont(d4f767463ce0a6b3).(m_FontHandlecxx . . $ UIEdit#m_FontHandle.); |
| 294 | |
| 295 | // I need an extra character. |
| 296 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(strlen(m_TextBuf) < sizeof(buffer)); |
| 297 | |
| 298 | if (m_Flagscxx . . $ UIGadget#m_Flags. & UIED_PASSWORDcxx . . $ `ui/ui.h:361:9`!) { |
| 299 | memset(buffer, '*', strlen(m_TextBufcxx . . $ UIEdit#m_TextBuf.)); |
| 300 | buffer[strlen(m_TextBufcxx . . $ UIEdit#m_TextBuf.)] = 0; |
| 301 | } else { |
| 302 | strcpy(buffer, m_TextBufcxx . . $ UIEdit#m_TextBuf.); |
| 303 | } |
| 304 | |
| 305 | if (m_Activecxx . . $ UIEdit#m_Active. || HasFocuscxx . . $ UIGadget#HasFocus(50ce9a9e25b4a850).()) |
| 306 | ui_SetCharAlphacxx . . $ ui_SetCharAlpha(ac50b47256ae7414).(255); |
| 307 | else |
| 308 | ui_SetCharAlphacxx . . $ ui_SetCharAlpha(ac50b47256ae7414).(164); |
| 309 | |
| 310 | if (IsDisabledcxx . . $ UIGadget#IsDisabled(c9857a73d68e59ba).()) |
| 311 | ui_SetCharAlphacxx . . $ ui_SetCharAlpha(ac50b47256ae7414).(96); |
| 312 | |
| 313 | // we must set StartPos if StartPos is -1 |
| 314 | if (m_StartPoscxx . . $ UIEdit#m_StartPos. < 0) { |
| 315 | m_StartPoscxx . . $ UIEdit#m_StartPos. = 0; |
| 316 | cursor_w = ui_GetTextWidthcxx . . $ ui_GetTextWidth(5c4306d8553b3696).("_"); |
| 317 | str_w = ui_GetTextWidthcxx . . $ ui_GetTextWidth(5c4306d8553b3696).(&buffer[m_StartPoscxx . . $ UIEdit#m_StartPos.]); |
| 318 | while ((m_X1bcxx . . $ UIEdit#m_X1b. + str_w) > (m_X2bcxx . . $ UIEdit#m_X2b. - cursor_w)) { |
| 319 | m_StartPoscxx . . $ UIEdit#m_StartPos.++; |
| 320 | str_w = ui_GetTextWidthcxx . . $ ui_GetTextWidth(5c4306d8553b3696).(&buffer[m_StartPoscxx . . $ UIEdit#m_StartPos.]); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | // determine how much of string to draw at one time. |
| 325 | i = 0; |
| 326 | |
| 327 | cursor_w = ui_GetTextWidthcxx . . $ ui_GetTextWidth(5c4306d8553b3696).("_") * 2; |
| 328 | str_w = ui_GetTextWidthcxx . . $ ui_GetTextWidth(5c4306d8553b3696).(&buffer[m_StartPoscxx . . $ UIEdit#m_StartPos.]); |
| 329 | while ((m_X1bcxx . . $ UIEdit#m_X1b. + str_w) > (m_X2bcxx . . $ UIEdit#m_X2b. - cursor_w) && ((int)strlen(buffer) > m_StartPoscxx . . $ UIEdit#m_StartPos.)) { |
| 330 | buffer[strlen(buffer) - 1] = 0; |
| 331 | str_w = ui_GetTextWidthcxx . . $ ui_GetTextWidth(5c4306d8553b3696).(&buffer[m_StartPoscxx . . $ UIEdit#m_StartPos.]); |
| 332 | i++; |
| 333 | } |
| 334 | |
| 335 | // if i is > 0, then the string displayed overlaps the boundaries of the listbox |
| 336 | m_ScrollThreshcxx . . $ UIEdit#m_ScrollThresh. = i ? (strlen(buffer)) : 0; |
| 337 | |
| 338 | if (m_ScrollThreshcxx . . $ UIEdit#m_ScrollThresh. && m_UpdateCountcxx . . $ UIEdit#m_UpdateCount.) { |
| 339 | m_StartPoscxx . . $ UIEdit#m_StartPos.++; |
| 340 | m_UpdateCountcxx . . $ UIEdit#m_UpdateCount. = false; |
| 341 | } |
| 342 | |
| 343 | // if cursor position is outside viewing region, we must adjust the viewing region. |
| 344 | // i = strlen(buffer); |
| 345 | // while (m_CurPos > i) |
| 346 | // m_CurPos--; |
| 347 | |
| 348 | ui_DrawSetTextTypecxx . . $ ui_DrawSetTextType(d4f767463ce0a6b3).(0); |
| 349 | ui_DrawStringcxx . . $ ui_DrawString(c261e420eb73c8b5).(m_Colorcxx . . $ UIEdit#m_Color., m_X1bcxx . . $ UIEdit#m_X1b., m_Ybcxx . . $ UIEdit#m_Yb. + (m_Hcxx . . $ UIObject#m_H. / 2 - ui_GetFontHeightcxx . . $ ui_GetFontHeight(b126dc7c1de90089).() / 2), &buffer[m_StartPoscxx . . $ UIEdit#m_StartPos.]); |
| 350 | |
| 351 | if (m_Activecxx . . $ UIEdit#m_Active.) { |
| 352 | buffer[m_CurPoscxx . . $ UIEdit#m_CurPos.] = 0; |
| 353 | str_w = ui_GetTextWidthcxx . . $ ui_GetTextWidth(5c4306d8553b3696).(buffer + m_StartPoscxx . . $ UIEdit#m_StartPos.); |
| 354 | if (((int)UI_TIMEcxx . . $ UI_TIME(9b8c9e39889c762c).()) % 2) |
| 355 | ui_DrawStringcxx . . $ ui_DrawString(c261e420eb73c8b5).(m_Colorcxx . . $ UIEdit#m_Color., m_X1bcxx . . $ UIEdit#m_X1b. + str_w + 1, m_Ybcxx . . $ UIEdit#m_Yb. + (m_Hcxx . . $ UIObject#m_H. / 2 - ui_GetFontHeightcxx . . $ ui_GetFontHeight(b126dc7c1de90089).() / 2), "_"); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | // behavior when key is pressed. |
| 360 | void UIEditcxx . . $ UIEdit#::OnKeyDowncxx . . $ UIEdit#OnKeyDown(d4f767463ce0a6b3).(int key) { |
| 361 | int ascii = grfont_KeyToAsciicxx . . $ grfont_KeyToAscii(9b79fb6aee4c0440).(m_FontHandlecxx . . $ UIEdit#m_FontHandle., key); |
| 362 | int len = strlen(m_TextBufcxx . . $ UIEdit#m_TextBuf.); |
| 363 | int i; |
| 364 | |
| 365 | if (!m_Activecxx . . $ UIEdit#m_Active.) { |
| 366 | UIEditcxx . . $ UIEdit#::Activatecxx . . $ UIEdit#Activate(49f6e7a06ebc5aa8).(); |
| 367 | } |
| 368 | |
| 369 | if (key == KEY_ESCcxx . . $ `ddio/ddio_common.h:267:9`! || key == KEY_ENTERcxx . . $ `ddio/ddio_common.h:268:9`!) { |
| 370 | UIEditcxx . . $ UIEdit#::Deactivatecxx . . $ UIEdit#Deactivate(49f6e7a06ebc5aa8).(); |
| 371 | if (key == KEY_ENTERcxx . . $ `ddio/ddio_common.h:268:9`!) { |
| 372 | UIGadgetcxx . . $ UIGadget#::OnSelectcxx . . $ UIGadget#OnSelect(49f6e7a06ebc5aa8).(); // do this to enforce pressing enter ONLY causes OnSelect to work. |
| 373 | } |
| 374 | } else if (key == KEY_DELETEcxx . . $ `ddio/ddio_common.h:315:9`!) { |
| 375 | for (i = m_CurPoscxx . . $ UIEdit#m_CurPos.; i < len; i++) |
| 376 | m_TextBufcxx . . $ UIEdit#m_TextBuf.[i] = m_TextBufcxx . . $ UIEdit#m_TextBuf.[i + 1]; |
| 377 | } else { |
| 378 | if (m_CurPoscxx . . $ UIEdit#m_CurPos. < m_BufSizecxx . . $ UIEdit#m_BufSize.) { |
| 379 | if (CHECK_FLAGcxx . . $ `lib/Macros.h:63:9`!(m_Flags, UIED_NUMBERScxx . . $ `ui/ui.h:362:9`!)) { |
| 380 | if (ascii < '0' || ascii > '9') { |
| 381 | goto skip_add_to_buffer; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | if (ascii >= 32 && ascii < 127 && len < m_BufSizecxx . . $ UIEdit#m_BufSize.) { |
| 386 | // insert character |
| 387 | for (i = len; i >= m_CurPoscxx . . $ UIEdit#m_CurPos.; i--) |
| 388 | m_TextBufcxx . . $ UIEdit#m_TextBuf.[i + 1] = m_TextBufcxx . . $ UIEdit#m_TextBuf.[i]; |
| 389 | // adjust scroll region if cursor will go out of visible region. |
| 390 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "scroll=%d, curpos=%d\n", m_ScrollThresh, m_CurPos); |
| 391 | // if (m_ScrollThresh<=m_CurPos && m_ScrollThresh) |
| 392 | // m_StartPos++; |
| 393 | m_TextBufcxx . . $ UIEdit#m_TextBuf.[m_CurPoscxx . . $ UIEdit#m_CurPos.++] = (char)ascii; |
| 394 | m_UpdateCountcxx . . $ UIEdit#m_UpdateCount. = true; |
| 395 | if (m_CurPoscxx . . $ UIEdit#m_CurPos. == m_BufSizecxx . . $ UIEdit#m_BufSize. && CHECK_FLAGcxx . . $ `lib/Macros.h:63:9`!(m_Flags, UIED_AUTOSELECTcxx . . $ `ui/ui.h:363:9`!)) { |
| 396 | UIEditcxx . . $ UIEdit#::Deactivatecxx . . $ UIEdit#Deactivate(49f6e7a06ebc5aa8).(); |
| 397 | UIGadgetcxx . . $ UIGadget#::OnSelectcxx . . $ UIGadget#OnSelect(49f6e7a06ebc5aa8).(); |
| 398 | return; |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | skip_add_to_buffer: |
| 404 | if (m_CurPoscxx . . $ UIEdit#m_CurPos. < len) { |
| 405 | if (key == KEY_RIGHTcxx . . $ `ddio/ddio_common.h:321:9`!) { |
| 406 | if (m_ScrollThreshcxx . . $ UIEdit#m_ScrollThresh. <= m_CurPoscxx . . $ UIEdit#m_CurPos. && m_ScrollThreshcxx . . $ UIEdit#m_ScrollThresh.) { |
| 407 | m_StartPoscxx . . $ UIEdit#m_StartPos.++; |
| 408 | } |
| 409 | // Update_count = true; |
| 410 | m_CurPoscxx . . $ UIEdit#m_CurPos.++; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | if (m_CurPoscxx . . $ UIEdit#m_CurPos. > 0) { |
| 415 | if (key == KEY_LEFTcxx . . $ `ddio/ddio_common.h:320:9`!) { |
| 416 | m_CurPoscxx . . $ UIEdit#m_CurPos.--; |
| 417 | } else if (key == KEY_BACKSPcxx . . $ `ddio/ddio_common.h:269:9`!) { |
| 418 | // delete character |
| 419 | for (i = m_CurPoscxx . . $ UIEdit#m_CurPos. - 1; i < len; i++) |
| 420 | m_TextBufcxx . . $ UIEdit#m_TextBuf.[i] = m_TextBufcxx . . $ UIEdit#m_TextBuf.[i + 1]; |
| 421 | |
| 422 | m_CurPoscxx . . $ UIEdit#m_CurPos.--; |
| 423 | } |
| 424 | if (m_CurPoscxx . . $ UIEdit#m_CurPos. < m_StartPoscxx . . $ UIEdit#m_StartPos.) |
| 425 | m_StartPoscxx . . $ UIEdit#m_StartPos. = m_CurPoscxx . . $ UIEdit#m_CurPos.; |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | // behavior when key is released. |
| 431 | void UIEditcxx . . $ UIEdit#::OnKeyUpcxx . . $ UIEdit#OnKeyUp(d4f767463ce0a6b3).(int key) {} |
| 432 | |
| 433 | // behavior when mouse button is pressed. |
| 434 | void UIEditcxx . . $ UIEdit#::OnMouseBtnDowncxx . . $ UIEdit#OnMouseBtnDown(d4f767463ce0a6b3).(int btn) { |
| 435 | if (btn == UILMSEBTNcxx . . $ `ui/uisys.h:36:9`!) { |
| 436 | if (!m_Activecxx . . $ UIEdit#m_Active.) { |
| 437 | UIEditcxx . . $ UIEdit#::Activatecxx . . $ UIEdit#Activate(49f6e7a06ebc5aa8).(); |
| 438 | } else if (!PT_IN_GADGETcxx . . $ PT_IN_GADGET(55d2799d541f12b5).(m_Wndcxx . . $ UIGadget#m_Wnd., this, UI_inputcxx . . $ UI_input..mxcxx . . $ tUIInput#mx., UI_inputcxx . . $ UI_input..mycxx . . $ tUIInput#my.) && m_Wndcxx . . $ UIGadget#m_Wnd.->GetFocuscxx . . $ UIWindow#GetFocus(42baa2535cd0f5f7).()) { |
| 439 | // click outside control and in another control, then deactivate, this means we've accepted the input. |
| 440 | UIEditcxx . . $ UIEdit#::Deactivatecxx . . $ UIEdit#Deactivate(49f6e7a06ebc5aa8).(); |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | // behavior when mouse button is released. |
| 446 | void UIEditcxx . . $ UIEdit#::OnMouseBtnUpcxx . . $ UIEdit#OnMouseBtnUp(d4f767463ce0a6b3).(int btn) {} |
| 447 | |
| 448 | void UIEditcxx . . $ UIEdit#::OnSelectcxx . . $ UIEdit#OnSelect(49f6e7a06ebc5aa8).() { |
| 449 | // except do this to release key focus on this edit box. |
| 450 | UIEditcxx . . $ UIEdit#::Deactivatecxx . . $ UIEdit#Deactivate(49f6e7a06ebc5aa8).(); |
| 451 | UIGadgetcxx . . $ UIGadget#::OnSelectcxx . . $ UIGadget#OnSelect(49f6e7a06ebc5aa8).(); |
| 452 | } |