Debian Codegraph @

ui/UIListBox.cpp

raw symbols SCIP
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/UIListBox.cpp $
21 * $Revision: 42 $
22 * $Date: 4/30/99 6:49p $
23 * $Author: Samir $
24 *
25 * Listbox code
26 *
27 * $Log: /DescentIII/Main/ui/UIListBox.cpp $
28 *
29 * 42 4/30/99 6:49p Samir
30 * fixed bug when scroll down with keyboard in last visible item of
31 * listbox.
32 *
33 * 41 4/14/99 1:53a Jeff
34 * fixed case mismatched #includes
35 *
36 * 40 3/22/99 1:55p Jeff
37 * fixed more crashes
38 *
39 * 39 3/22/99 12:47p Jeff
40 * oops...fixed some listbox crashes
41 *
42 * 38 3/19/99 9:21p Jeff
43 * fixed some listbox sorting issues
44 *
45 * 37 2/24/99 1:14p Jeff
46 * fixed sorting bug when you have 2 identical items
47 *
48 * 36 2/21/99 6:36p Samir
49 * focusing changes and key input changes to ui.,
50 *
51 * 35 2/04/99 12:10p Jeff
52 * fixed SelectItem
53 *
54 * 34 1/27/99 10:26p Jeff
55 * fixed sorting bug, very odd it hasn't cropped up before, only happened
56 * when allocating a new buffer of indices
57 *
58 * 32 10/19/98 6:30p Jeff
59 * changes made for detail variables. Put in preset values. Preset
60 * options. Removed terrain_cast from detail. Put new callbacks in
61 * UIListBox and UISlider
62 *
63 * 31 10/06/98 8:05p Samir
64 * added page up and page down!
65 *
66 * 30 10/06/98 7:30p Samir
67 * scrolling listbox is cleaner.
68 *
69 * 29 9/30/98 4:33p Samir
70 * listbox broke for keyboard for now.
71 *
72 * 28 9/22/98 3:57p Samir
73 * listbox prob fixed again.
74 *
75 * 27 9/10/98 6:32p Samir
76 * changed some visual characteristics of listboxes.
77 *
78 * 26 9/02/98 6:50p Samir
79 * fixed some double clicking issues for listboxes.
80 *
81 * 25 8/31/98 12:37p Samir
82 * SetSelectedIndex modifies visible index as well, and dblclick works
83 * again.
84 *
85 * 24 8/25/98 5:27p Samir
86 * new focusing rules for keyboard.
87 *
88 * 23 8/24/98 3:12p Samir
89 * fixed text clipping
90 *
91 * 22 8/11/98 11:38a Samir
92 * fixed listbox probs yet again. arrows on side this time.
93 *
94 * 21 7/29/98 3:26p Samir
95 * fixed some listbox mouse problems.
96 *
97 * 20 7/28/98 7:13p Samir
98 * reset index when removing all items.
99 *
100 * 19 7/15/98 2:26p Samir
101 * may have fixed something with arrows.
102 *
103 * 18 6/22/98 2:15p Samir
104 * implemented border flag.
105 *
106 * 17 6/05/98 5:36p Samir
107 * cleaner keyboard inteface for listboxes.
108 *
109 * 16 4/29/98 1:04p Jeff
110 * fixed up the UIListBox a bit (color control and scroll buttons)
111 *
112 * 15 4/29/98 11:55a Samir
113 * allow user to change color of selected listbox item.
114 *
115 * 14 4/13/98 7:02p Samir
116 * made some things protected.
117 *
118 * 13 3/16/98 11:43a Brent
119 * (Jeff) fixed UIListBox so it doesn't draw arrows if nothing in the box
120 *
121 * 12 3/13/98 5:19p Jeff
122 * added scroll button code
123 *
124 * 11 3/09/98 5:08p Samir
125 * fixed bug.
126 *
127 * 10 3/09/98 5:05p Samir
128 * Added callback to selection change function.
129 *
130 * 9 3/09/98 3:43p Samir
131 * Single clicks should select an item in a listbox.
132 *
133 * 8 2/24/98 3:05p Samir
134 * don't set listindex when selecting.
135 *
136 * 7 2/15/98 7:07p Samir
137 * Listbox now supports up and down arrow keys.
138 *
139 * 6 2/13/98 6:36p Samir
140 * Double click to select.
141 *
142 * 5 2/10/98 4:56p Samir
143 * Listbox with alphas and a selection bar.
144 *
145 * 4 2/10/98 3:45p Samir
146 * Fixed bug in drawing items over the boundaries of the listbox.
147 *
148 * 3 1/30/98 7:07p Samir
149 * Simple box containing items. Must be handled by a parent.
150 *
151 * 2 1/13/98 4:28p Samir
152 * Fixed typo.
153 *
154 * 1 1/09/98 12:00p Samir
155 * Initial revision
156 *
157 * $NoKeywords: $
158 */
159
160 #include <cstdlib>
161 #include <cstring>
162
163 #include "UIlib.h"cxx . . $ `<file>/ui/UIlib.h`/
164
165 #define SCROLL_BUTTON_GAPcxx . . $ `ui/UIListBox.cpp:165:9`! 4
166
167 // Construction and destruction
168
169 UIListBoxcxx . . $ UIListBox#::UIListBoxcxx . . $ UIListBox#UIListBox(49f6e7a06ebc5aa8).() {
170 m_NumItemscxx . . $ UIListBox#m_NumItems. = 0;
171 m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. = 0;
172 m_Indexcxx . . $ UIListBox#m_Index. = 0;
173 m_ItemListcxx . . $ UIListBox#m_ItemList. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
174 m_Virt2Realcxx . . $ UIListBox#m_Virt2Real. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
175 m_Real2Virtcxx . . $ UIListBox#m_Real2Virt. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
176 m_MouseStatecxx . . $ UIListBox#m_MouseState. = 0;
177 selectchange_fncxx . . $ UIListBox#selectchange_fn. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
178 selectchange_id_fncxx . . $ UIListBox#selectchange_id_fn. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
179 m_callbackptrcxx . . $ UIListBox#m_callbackptr. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
180 m_TextOffXcxx . . $ UIListBox#m_TextOffX. = 4;
181 m_TextOffYcxx . . $ UIListBox#m_TextOffY. = 4;
182 }
183
184 UIListBoxcxx . . $ UIListBox#::~cxx . . $ UIListBox#`~UIListBox`(ced63f7c635d850d).UIListBoxcxx . . $ UIListBox#() {}
185
186 void UIListBoxcxx . . $ UIListBox#::Createcxx . . $ UIListBox#Create(43707b8add2f137d).(UIWindowcxx . . $ UIWindow# *parent, int id, int x, int y, int w, int h, int flags) {
187 m_NumItemscxx . . $ UIListBox#m_NumItems. = 0;
188 m_ItemListcxx . . $ UIListBox#m_ItemList. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
189 m_Virt2Realcxx . . $ UIListBox#m_Virt2Real. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
190 m_Real2Virtcxx . . $ UIListBox#m_Real2Virt. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
191 m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. = 0;
192 m_Indexcxx . . $ UIListBox#m_Index. = 0;
193 m_MouseStatecxx . . $ UIListBox#m_MouseState. = 0;
194 m_ClickTimecxx . . $ UIListBox#m_ClickTime. = 0;
195 selectchange_fncxx . . $ UIListBox#selectchange_fn. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
196 selectchange_id_fncxx . . $ UIListBox#selectchange_id_fn. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
197 m_callbackptrcxx . . $ UIListBox#m_callbackptr. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
198 m_ShowDowncxx . . $ UIListBox#m_ShowDown. = false;
199 m_ShowUpcxx . . $ UIListBox#m_ShowUp. = false;
200 m_SelectColorcxx . . $ UIListBox#m_SelectColor. = GR_WHITEcxx . . $ GR_WHITE.;
201 m_HiliteColorcxx . . $ UIListBox#m_HiliteColor. = GR_DARKGRAYcxx . . $ GR_DARKGRAY.;
202 m_NumVisibleItemscxx . . $ UIListBox#m_NumVisibleItems. = 0;
203 m_Alphacxx . . $ UIListBox#m_Alpha. = 192;
204
205 UIGadgetcxx . . $ UIGadget#::Createcxx . . $ UIGadget#Create(43707b8add2f137d).(parent, id, x, y, w, h, flags);
206 m_CXcxx . . $ UIListBox#m_CX. = 1;
207 m_CYcxx . . $ UIListBox#m_CY. = 1;
208 m_CX2cxx . . $ UIListBox#m_CX2. = m_Wcxx . . $ UIObject#m_W. - 1;
209 m_CY2cxx . . $ UIListBox#m_CY2. = m_Hcxx . . $ UIObject#m_H. - 1;
210 }
211
212 // settings
213
214 // adds an item to the list, no sorting
215 void UIListBoxcxx . . $ UIListBox#::AddItemcxx . . $ UIListBox#AddItem(f57aa2fef0df48a8).(const UIItemcxx . . $ UIItem# *item) {
216 UIItemcxx . . $ UIItem# **temp;
217 int i;
218 int *tempvirt2real, *tempreal2virt;
219 int real_index = -1;
220
221 if (m_Flagscxx . . $ UIGadget#m_Flags. & UILB_NOSORTcxx . . $ `ui/ui.h:356:9`!) {
222 // insert without sort
223
224 if ((m_NumItemscxx . . $ UIListBox#m_NumItems. % LISTBOX_BUFFER_SIZEcxx . . $ `ui/ui.h:879:9`!) == 0) {
225 // dynamically allocated memory for listbox, expand as needed.
226 temp = new UIItemcxx . . $ UIItem# *[m_NumItemscxx . . $ UIListBox#m_NumItems. + LISTBOX_BUFFER_SIZEcxx . . $ `ui/ui.h:879:9`!];
227 tempvirt2real = new int[m_NumItemscxx . . $ UIListBox#m_NumItems. + LISTBOX_BUFFER_SIZEcxx . . $ `ui/ui.h:879:9`!];
228 tempreal2virt = new int[m_NumItemscxx . . $ UIListBox#m_NumItems. + LISTBOX_BUFFER_SIZEcxx . . $ `ui/ui.h:879:9`!];
229
230 if (m_ItemListcxx . . $ UIListBox#m_ItemList.) {
231 for (i = 0; i < m_NumItemscxx . . $ UIListBox#m_NumItems.; i++) {
232 temp[i] = m_ItemListcxx . . $ UIListBox#m_ItemList.[i];
233 tempvirt2real[i] = m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.[i];
234 tempreal2virt[i] = m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[i];
235 }
236
237 delete[] m_ItemListcxx . . $ UIListBox#m_ItemList.;
238 delete[] m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.;
239 delete[] m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.;
240 }
241 m_ItemListcxx . . $ UIListBox#m_ItemList. = temp;
242 m_Virt2Realcxx . . $ UIListBox#m_Virt2Real. = tempvirt2real;
243 m_Real2Virtcxx . . $ UIListBox#m_Real2Virt. = tempreal2virt;
244 }
245
246 real_index = m_NumItemscxx . . $ UIListBox#m_NumItems.;
247
248 } else {
249 // only text item listboxes!
250
251 // insert with sorting
252 if ((m_NumItemscxx . . $ UIListBox#m_NumItems. % LISTBOX_BUFFER_SIZEcxx . . $ `ui/ui.h:879:9`!) == 0) {
253 // dynamically allocated memory for listbox, expand as needed.
254 temp = new UIItemcxx . . $ UIItem# *[m_NumItemscxx . . $ UIListBox#m_NumItems. + LISTBOX_BUFFER_SIZEcxx . . $ `ui/ui.h:879:9`!];
255 tempvirt2real = new int[m_NumItemscxx . . $ UIListBox#m_NumItems. + LISTBOX_BUFFER_SIZEcxx . . $ `ui/ui.h:879:9`!];
256 tempreal2virt = new int[m_NumItemscxx . . $ UIListBox#m_NumItems. + LISTBOX_BUFFER_SIZEcxx . . $ `ui/ui.h:879:9`!];
257 int oidx = 0, cidx = 0;
258 int pidx = 0;
259 real_index = -1;
260 int result;
261
262 if (m_ItemListcxx . . $ UIListBox#m_ItemList.) {
263 while (oidx <= m_NumItemscxx . . $ UIListBox#m_NumItems.) {
264 if (oidx == m_NumItemscxx . . $ UIListBox#m_NumItems.) {
265 if (real_index == -1) {
266 real_index = oidx;
267 } else {
268 temp[cidx] = m_ItemListcxx . . $ UIListBox#m_ItemList.[pidx];
269 tempreal2virt[cidx] = m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[pidx];
270 }
271 oidx++;
272 continue;
273 }
274
275 if (m_Flagscxx . . $ UIGadget#m_Flags. & UILB_CASESENSITIVEcxx . . $ `ui/ui.h:357:9`!)
276 result = strcmp(((UITextItemcxx . . $ UITextItem# *)m_ItemListcxx . . $ UIListBox#m_ItemList.[cidx])->GetBuffercxx . . $ UITextItem#GetBuffer(a9f41ea0e82d88cf).(), ((UITextItemcxx . . $ UITextItem# *)item)->GetBuffercxx . . $ UITextItem#GetBuffer(a9f41ea0e82d88cf).());
277 else
278 result = stricmpcxx . . $ `linux/linux_fix.h:43:9`!(((UITextItem *)m_ItemList[cidx])->GetBuffer(), ((UITextItem *)item)->GetBuffer());
279 if (result < 0) {
280 // copy old
281 temp[cidx] = m_ItemListcxx . . $ UIListBox#m_ItemList.[pidx];
282 tempreal2virt[cidx] = m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[pidx];
283 cidx++;
284 pidx++;
285 } else if (result >= 0) {
286 // see if we need to insert, if not just keep copying
287 if (real_index == -1) {
288 real_index = cidx;
289 cidx++;
290 } else {
291 temp[cidx] = m_ItemListcxx . . $ UIListBox#m_ItemList.[pidx];
292 tempreal2virt[cidx] = m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[pidx];
293 cidx++;
294 pidx++;
295 }
296 }
297 oidx++;
298 }
299 ASSERTcxx . . $ `misc/pserror.h:246:9`!(real_index != -1);
300
301 // now we need to fix m_Virt2Real to represent the new structure,
302 // all values>=real_index must be incremented
303 for (oidx = 0; oidx <= m_NumItemscxx . . $ UIListBox#m_NumItems.; oidx++) {
304 if (oidx < m_NumItemscxx . . $ UIListBox#m_NumItems.) {
305 tempvirt2real[oidx] = m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.[oidx];
306
307 // if(oidx!=real_index){
308 if (tempvirt2real[oidx] >= real_index)
309 tempvirt2real[oidx]++;
310 }
311 }
312
313 delete[] m_ItemListcxx . . $ UIListBox#m_ItemList.;
314 delete[] m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.;
315 delete[] m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.;
316 } else {
317 real_index = 0;
318 }
319
320 m_ItemListcxx . . $ UIListBox#m_ItemList. = temp;
321 m_Virt2Realcxx . . $ UIListBox#m_Virt2Real. = tempvirt2real;
322 m_Real2Virtcxx . . $ UIListBox#m_Real2Virt. = tempreal2virt;
323 } else {
324 // find where to insert, without allocating memory
325 int oidx = 0, cidx = 0;
326 real_index = -1;
327 int result;
328
329 int old_r2v;
330 UIItemcxx . . $ UIItem# *old_item = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
331
332 while (oidx <= m_NumItemscxx . . $ UIListBox#m_NumItems.) {
333
334 if (oidx == m_NumItemscxx . . $ UIListBox#m_NumItems.) {
335 // we're past the slot of the old buffer
336 if (real_index == -1) {
337 // we haven't set the real index yet, so it has to go here
338 real_index = m_NumItemscxx . . $ UIListBox#m_NumItems.;
339 } else {
340 // the real index has been set, we're still pulling back
341 m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[cidx] = old_r2v;
342 m_ItemListcxx . . $ UIListBox#m_ItemList.[cidx] = old_item;
343 }
344 oidx++;
345 continue;
346 } else {
347 if (m_Flagscxx . . $ UIGadget#m_Flags. & UILB_CASESENSITIVEcxx . . $ `ui/ui.h:357:9`!)
348 result = strcmp(((UITextItemcxx . . $ UITextItem# *)m_ItemListcxx . . $ UIListBox#m_ItemList.[cidx])->GetBuffercxx . . $ UITextItem#GetBuffer(a9f41ea0e82d88cf).(), ((UITextItemcxx . . $ UITextItem# *)item)->GetBuffercxx . . $ UITextItem#GetBuffer(a9f41ea0e82d88cf).());
349 else
350 result = stricmpcxx . . $ `linux/linux_fix.h:43:9`!(((UITextItem *)m_ItemList[cidx])->GetBuffer(), ((UITextItem *)item)->GetBuffer());
351 }
352
353 if (result < 0) {
354 // we haven't gotten to the string yet, keep as they are
355 cidx++;
356 } else if (result >= 0) {
357 // see if we need to insert, if not just keep copying
358 if (real_index == -1) {
359 // we need to insert here
360 real_index = cidx;
361 old_item = m_ItemListcxx . . $ UIListBox#m_ItemList.[cidx];
362 old_r2v = m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[cidx];
363 cidx++;
364 } else {
365 // old_item and old_r2v should be set!
366 ASSERTcxx . . $ `misc/pserror.h:246:9`!(old_item);
367 UIItemcxx . . $ UIItem# *oi;
368 int or2v;
369
370 or2v = m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[cidx];
371 oi = m_ItemListcxx . . $ UIListBox#m_ItemList.[cidx];
372
373 m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[cidx] = old_r2v;
374 m_ItemListcxx . . $ UIListBox#m_ItemList.[cidx] = old_item;
375 old_r2v = or2v;
376 old_item = oi;
377
378 cidx++;
379 }
380 }
381
382 // continue on
383 oidx++;
384 }
385
386 ASSERTcxx . . $ `misc/pserror.h:246:9`!(real_index != -1);
387
388 // now we need to fix m_Virt2Real to represent the new structure,
389 // all values>=real_index must be incremented
390 cidx = 0;
391 for (oidx = 0; oidx <= m_NumItemscxx . . $ UIListBox#m_NumItems.; oidx++) {
392 if (oidx != real_index) {
393 if (m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.[cidx] >= real_index)
394 m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.[cidx]++;
395 cidx++;
396 }
397 }
398 }
399 }
400
401 // copy item passed to list.
402 m_ItemListcxx . . $ UIListBox#m_ItemList.[real_index] = (UIItemcxx . . $ UIItem# *)item;
403 m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.[m_NumItemscxx . . $ UIListBox#m_NumItems.] = real_index;
404 m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[real_index] = m_NumItemscxx . . $ UIListBox#m_NumItems.;
405 m_NumItemscxx . . $ UIListBox#m_NumItems.++;
406
407 if (real_index <= m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex.) {
408 // adjust selected index
409 if (m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. < m_NumItemscxx . . $ UIListBox#m_NumItems. - 1)
410 m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex.++;
411 }
412 }
413
414 // removes an item from the list.
415 void UIListBoxcxx . . $ UIListBox#::RemoveItemcxx . . $ UIListBox#RemoveItem(f57aa2fef0df48a8).(const UIItemcxx . . $ UIItem# *item) {
416 int i, j, found = -1;
417
418 for (i = 0; i < m_NumItemscxx . . $ UIListBox#m_NumItems.; i++) {
419 if (item == m_ItemListcxx . . $ UIListBox#m_ItemList.[i]) {
420 found = i;
421 break;
422 }
423 }
424 if (found == -1) {
425 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "UIListBox:: Didn't find item to remove!\n");
426 return;
427 }
428
429 // found is the real index to remove
430 // go through virt2real and subtract one from values of found or higher
431 // go through real2virt and move everything from index found on down, and subtract
432 // 1 from those with value of found or higher
433 int real_index = found; // index to remove
434 int virt_index = m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[found]; // index to remove
435 int real_thresh = virt_index;
436 int virt_thresh = real_index;
437
438 for (j = 0; j < (m_NumItemscxx . . $ UIListBox#m_NumItems. - 1); j++) {
439 if (j >= real_index) {
440 m_ItemListcxx . . $ UIListBox#m_ItemList.[j] = m_ItemListcxx . . $ UIListBox#m_ItemList.[j + 1];
441 m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[j] = m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[j + 1];
442 }
443
444 if (j >= virt_index) {
445 m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.[j] = m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.[j + 1];
446 }
447
448 if (m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[j] >= real_thresh)
449 m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[j]--;
450
451 if (m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.[j] >= virt_thresh)
452 m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.[j]--;
453 }
454 m_NumItemscxx . . $ UIListBox#m_NumItems.--;
455
456 if (real_index <= m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex.) {
457 // adjust selected index
458 if (m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. > 0)
459 m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex.--;
460 }
461 }
462
463 // empties listbox
464 void UIListBoxcxx . . $ UIListBox#::RemoveAllcxx . . $ UIListBox#RemoveAll(49f6e7a06ebc5aa8).() {
465 m_Indexcxx . . $ UIListBox#m_Index. = m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. = m_NumItemscxx . . $ UIListBox#m_NumItems. = 0;
466 if (m_ItemListcxx . . $ UIListBox#m_ItemList.)
467 delete[] m_ItemListcxx . . $ UIListBox#m_ItemList.;
468 if (m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.)
469 delete[] m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.;
470 if (m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.)
471 delete[] m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.;
472 m_ItemListcxx . . $ UIListBox#m_ItemList. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
473 m_Virt2Realcxx . . $ UIListBox#m_Virt2Real. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
474 m_Real2Virtcxx . . $ UIListBox#m_Real2Virt. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
475 }
476
477 // selects the given item in the list.
478 void UIListBoxcxx . . $ UIListBox#::SelectItemcxx . . $ UIListBox#SelectItem(f57aa2fef0df48a8).(const UIItemcxx . . $ UIItem# *item) {
479 int i, found = 0;
480
481 for (i = 0; i < m_NumItemscxx . . $ UIListBox#m_NumItems.; i++) {
482 if (item == m_ItemListcxx . . $ UIListBox#m_ItemList.[i]) {
483 SetSelectedIndexcxx . . $ UIListBox#SetSelectedIndex(d4f767463ce0a6b3).(m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[i]);
484 found = 1;
485 break;
486 }
487 }
488 if (!found) {
489 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "UIListBox::SelectItem item not found!\n");
490 }
491 }
492
493 // returns the item at listbox index given.
494 UIItemcxx . . $ UIItem# *UIListBoxcxx . . $ UIListBox#::GetItemcxx . . $ UIListBox#GetItem(546e15a08a69e3a5).(int index) const {
495 if (m_NumItemscxx . . $ UIListBox#m_NumItems. == 0)
496 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
497
498 if (index >= 0 && index < m_NumItemscxx . . $ UIListBox#m_NumItems.) {
499 int real_index = m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.[index];
500 ASSERTcxx . . $ `misc/pserror.h:246:9`!(real_index >= 0 && real_index < m_NumItems);
501 return m_ItemListcxx . . $ UIListBox#m_ItemList.[real_index];
502 } else
503 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
504 }
505
506 // returns the current listbox index
507 int UIListBoxcxx . . $ UIListBox#::GetListIndexcxx . . $ UIListBox#GetListIndex(455f465bc33b4cdf).() const {
508 if (m_NumItemscxx . . $ UIListBox#m_NumItems. == 0)
509 return 0;
510
511 if (m_Indexcxx . . $ UIListBox#m_Index. < 0)
512 return m_Indexcxx . . $ UIListBox#m_Index.;
513
514 if (!m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.)
515 return 0;
516
517 int virt_index = m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[m_Indexcxx . . $ UIListBox#m_Index.];
518 ASSERTcxx . . $ `misc/pserror.h:246:9`!(virt_index >= 0 && virt_index < m_NumItems);
519
520 return virt_index;
521 }
522
523 // sets the index of a listbox
524 void UIListBoxcxx . . $ UIListBox#::SetListIndexcxx . . $ UIListBox#SetListIndex(d4f767463ce0a6b3).(int index) {
525 if (m_NumItemscxx . . $ UIListBox#m_NumItems. == 0)
526 return;
527
528 if (index >= 0 && index < m_NumItemscxx . . $ UIListBox#m_NumItems.) {
529 int real_index = m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.[index];
530 ASSERTcxx . . $ `misc/pserror.h:246:9`!(real_index >= 0 && real_index < m_NumItems);
531 m_Indexcxx . . $ UIListBox#m_Index. = real_index;
532 }
533 }
534
535 // returns which item index is selected
536 int UIListBoxcxx . . $ UIListBox#::GetSelectedIndexcxx . . $ UIListBox#GetSelectedIndex(455f465bc33b4cdf).() const {
537 if (m_NumItemscxx . . $ UIListBox#m_NumItems. == 0)
538 return 0;
539
540 if (m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. < 0)
541 return m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex.;
542
543 if (!m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.)
544 return 0;
545
546 int virt_index = m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex.];
547 ASSERTcxx . . $ `misc/pserror.h:246:9`!(virt_index >= 0 && virt_index < m_NumItems);
548 return virt_index;
549 }
550
551 // sets the selected index.
552 void UIListBoxcxx . . $ UIListBox#::SetSelectedIndexcxx . . $ UIListBox#SetSelectedIndex(d4f767463ce0a6b3).(int index) {
553 if (m_NumItemscxx . . $ UIListBox#m_NumItems. == 0)
554 return;
555
556 if (index >= 0 && index < m_NumItemscxx . . $ UIListBox#m_NumItems.) {
557 int real_index = m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.[index];
558 ASSERTcxx . . $ `misc/pserror.h:246:9`!(real_index >= 0 && real_index < m_NumItems);
559
560 int i, y = m_TextOffYcxx . . $ UIListBox#m_TextOffY.;
561 m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. = real_index;
562 for (i = 0; i < m_NumItemscxx . . $ UIListBox#m_NumItems.; i++) {
563 y += m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->heightcxx . . $ UIItem#height(b126dc7c1de90089).() + 2;
564 if (y > (m_Hcxx . . $ UIObject#m_H. - m_TextOffYcxx . . $ UIListBox#m_TextOffY.))
565 break;
566 }
567
568 m_Indexcxx . . $ UIListBox#m_Index. = m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. - i;
569 if (m_Indexcxx . . $ UIListBox#m_Index. < 0)
570 m_Indexcxx . . $ UIListBox#m_Index. = 0;
571
572 if (selectchange_fncxx . . $ UIListBox#selectchange_fn.)
573 (*selectchange_fncxx . . $ UIListBox#selectchange_fn.)(index);
574 if (selectchange_id_fncxx . . $ UIListBox#selectchange_id_fn.)
575 (*selectchange_id_fncxx . . $ UIListBox#selectchange_id_fn.)(GetIDcxx . . $ UIGadget#GetID(455f465bc33b4cdf).(), m_callbackptrcxx . . $ UIListBox#m_callbackptr.);
576 }
577 }
578
579 void UIListBoxcxx . . $ UIListBox#::SetInternalSelectedIndexcxx . . $ UIListBox#SetInternalSelectedIndex(d4f767463ce0a6b3).(int index) {
580 if (m_NumItemscxx . . $ UIListBox#m_NumItems. == 0)
581 return;
582
583 if (index >= 0 && index < m_NumItemscxx . . $ UIListBox#m_NumItems.) {
584 int real_index = m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.[index];
585 ASSERTcxx . . $ `misc/pserror.h:246:9`!(real_index >= 0 && real_index < m_NumItems);
586 m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. = real_index;
587
588 if (selectchange_fncxx . . $ UIListBox#selectchange_fn.)
589 (*selectchange_fncxx . . $ UIListBox#selectchange_fn.)(index);
590 if (selectchange_id_fncxx . . $ UIListBox#selectchange_id_fn.)
591 (*selectchange_id_fncxx . . $ UIListBox#selectchange_id_fn.)(GetIDcxx . . $ UIGadget#GetID(455f465bc33b4cdf).(), m_callbackptrcxx . . $ UIListBox#m_callbackptr.);
592 }
593 }
594
595 void UIListBoxcxx . . $ UIListBox#::SetSelectChangeCallbackcxx . . $ UIListBox#SetSelectChangeCallback(94eb4457dc8d4d10).(void (*fn)(int)) { selectchange_fncxx . . $ UIListBox#selectchange_fn. = fn; }
596
597 void UIListBoxcxx . . $ UIListBox#::SetSelectChangeCallbackcxx . . $ UIListBox#SetSelectChangeCallback(af3d7c1df3fe7292).(void (*fn)(int, void *), void *ptr) {
598 selectchange_id_fncxx . . $ UIListBox#selectchange_id_fn. = fn;
599 m_callbackptrcxx . . $ UIListBox#m_callbackptr. = ptr;
600 }
601
602 // called from outside gadget hierarchy.
603
604 void UIListBoxcxx . . $ UIListBox#::OnDestroycxx . . $ UIListBox#OnDestroy(49f6e7a06ebc5aa8).() {
605 UIGadgetcxx . . $ UIGadget#::OnDestroycxx . . $ UIGadget#OnDestroy(49f6e7a06ebc5aa8).();
606
607 if (m_ItemListcxx . . $ UIListBox#m_ItemList.)
608 delete[] m_ItemListcxx . . $ UIListBox#m_ItemList.;
609 if (m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.)
610 delete[] m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.;
611 if (m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.)
612 delete[] m_Virt2Realcxx . . $ UIListBox#m_Virt2Real.;
613
614 m_ItemListcxx . . $ UIListBox#m_ItemList. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
615 m_Real2Virtcxx . . $ UIListBox#m_Real2Virt. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
616 m_Virt2Realcxx . . $ UIListBox#m_Virt2Real. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
617 }
618
619 // behavior when gadget is being drawn.
620 void UIListBoxcxx . . $ UIListBox#::OnDrawcxx . . $ UIListBox#OnDraw(49f6e7a06ebc5aa8).() {
621 bool use_scroll = !(m_Flagscxx . . $ UIGadget#m_Flags. & UILB_NOSCROLLcxx . . $ `ui/ui.h:354:9`!);
622 bool auto_select = ((m_Flagscxx . . $ UIGadget#m_Flags. & UILB_AUTOSELECTcxx . . $ `ui/ui.h:355:9`!) > 0);
623 UITextItemcxx . . $ UITextItem# uarrowcxx . . $ UITextItem#UITextItem(49f6e7a06ebc5aa8).;
624 UITextItemcxx . . $ UITextItem# darrowcxx . . $ UITextItem#UITextItem(49f6e7a06ebc5aa8).;
625 char arrowbuf[2];
626
627 if (m_Flagscxx . . $ UIGadget#m_Flags. & UIF_BORDERcxx . . $ `ui/ui.h:344:9`!)
628 ui_DrawBoxcxx . . $ ui_DrawBox(fe09a4b73d8d396f).(GR_WHITEcxx . . $ GR_WHITE., 0, 0, m_Wcxx . . $ UIObject#m_W., m_Hcxx . . $ UIObject#m_H.);
629
630 ui_SetTextClipcxx . . $ ui_SetTextClip(748afa4755bc9595).(m_CXcxx . . $ UIListBox#m_CX., m_CYcxx . . $ UIListBox#m_CY., m_CX2cxx . . $ UIListBox#m_CX2., m_CY2cxx . . $ UIListBox#m_CY2.);
631
632 // draw all items in box that can be visible.
633 int x, y, i;
634 uint8_tcxx . . $ uint8_t# alpha;
635
636 x = m_TextOffXcxx . . $ UIListBox#m_TextOffX.;
637 y = m_TextOffYcxx . . $ UIListBox#m_TextOffY.;
638
639 if (m_NumItemscxx . . $ UIListBox#m_NumItems.) {
640 snprintf(arrowbuf, sizeof(arrowbuf), "%c", UI_UP_ARROW_CHARcxx . . $ `ui/UIlib.h:96:9`!);
641 uarrow =cxx . . $ UITextItem#`operator=`(5ad635489e71ed3b). UITextItemcxx . . $ UITextItem#UITextItem(5f8aa4f2725849c4).(arrowbuf, m_ItemListcxx . . $ UIListBox#m_ItemList.[m_Indexcxx . . $ UIListBox#m_Index.]->get_colorcxx . . $ UIItem#get_color(ddd8539a2fcdd4ce).(), 255);
642 snprintf(arrowbuf, sizeof(arrowbuf), "%c", UI_DOWN_ARROW_CHARcxx . . $ `ui/UIlib.h:98:9`!);
643 darrow =cxx . . $ UITextItem#`operator=`(5ad635489e71ed3b). UITextItemcxx . . $ UITextItem#UITextItem(5f8aa4f2725849c4).(arrowbuf, m_ItemListcxx . . $ UIListBox#m_ItemList.[m_Indexcxx . . $ UIListBox#m_Index.]->get_colorcxx . . $ UIItem#get_color(ddd8539a2fcdd4ce).(), 255);
644
645 // reset these
646 m_ShowUpcxx . . $ UIListBox#m_ShowUp. = m_ShowDowncxx . . $ UIListBox#m_ShowDown. = false;
647
648 if (use_scroll) {
649 m_UpArrowY0cxx . . $ UIListBox#m_UpArrowY0. = y;
650 m_UpArrowY1cxx . . $ UIListBox#m_UpArrowY1. = y + uarrow.heightcxx . . $ UITextItem#height(b126dc7c1de90089).();
651 if (m_Indexcxx . . $ UIListBox#m_Index. > 0)
652 uarrow.drawcxx . . $ UITextItem#draw(84329bcd07240ccf).(m_TextOffXcxx . . $ UIListBox#m_TextOffX., m_UpArrowY0cxx . . $ UIListBox#m_UpArrowY0., IsDisabledcxx . . $ UIGadget#IsDisabled(c9857a73d68e59ba).() ? uiDrawFadedcxx . . $ uiDrawFaded. : uiDrawNormalcxx . . $ uiDrawNormal.);
653 m_ShowUpcxx . . $ UIListBox#m_ShowUp. = true;
654 m_ArrowWidthcxx . . $ UIListBox#m_ArrowWidth. = uarrow.widthcxx . . $ UITextItem#width(b126dc7c1de90089).() + 2;
655 x = x + m_ArrowWidthcxx . . $ UIListBox#m_ArrowWidth.;
656 } else
657 m_ArrowWidthcxx . . $ UIListBox#m_ArrowWidth. = 0;
658 }
659
660 alpha = m_Alphacxx . . $ UIListBox#m_Alpha.;
661
662 for (i = m_Indexcxx . . $ UIListBox#m_Index.; i < m_NumItemscxx . . $ UIListBox#m_NumItems.; i++) {
663 // check to see if scroll arrow down needs to be drawn.
664 // if (m_SelectedIndex == i) {
665 // ui_DrawSetAlpha((alpha/4)+1);
666 // ui_DrawRect(m_HiliteColor, x,y,m_W-m_TextOffX,y+m_ItemList[i]->height()+2);
667 // }
668
669 m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->set_alphacxx . . $ UIItem#set_alpha(ac50b47256ae7414).((uint8_tcxx . . $ uint8_t#)alpha);
670 if (m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. == i) {
671 ddgr_colorcxx . . $ ddgr_color# old_color = m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->get_colorcxx . . $ UIItem#get_color(ddd8539a2fcdd4ce).();
672 m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->set_colorcxx . . $ UIItem#set_color(cb2f890c2fdad230).(m_SelectColorcxx . . $ UIListBox#m_SelectColor.);
673 m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->drawcxx . . $ UIItem#draw(84329bcd07240ccf).(x + 1, y + 1, IsDisabledcxx . . $ UIGadget#IsDisabled(c9857a73d68e59ba).() ? uiDrawFadedcxx . . $ uiDrawFaded. : uiDrawNormalcxx . . $ uiDrawNormal.);
674 if (!IsDisabledcxx . . $ UIGadget#IsDisabled(c9857a73d68e59ba).())
675 m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->drawcxx . . $ UIItem#draw(84329bcd07240ccf).(x + 1, y + 1, uiDrawAlphaSaturatecxx . . $ uiDrawAlphaSaturate.);
676 m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->set_colorcxx . . $ UIItem#set_color(cb2f890c2fdad230).(old_color);
677 } else {
678 m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->drawcxx . . $ UIItem#draw(84329bcd07240ccf).(x + 1, y + 1, IsDisabledcxx . . $ UIGadget#IsDisabled(c9857a73d68e59ba).() ? uiDrawFadedcxx . . $ uiDrawFaded. : uiDrawNormalcxx . . $ uiDrawNormal.);
679 }
680
681 if (use_scroll && (i < m_NumItemscxx . . $ UIListBox#m_NumItems.)) {
682 if ((y + m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->heightcxx . . $ UIItem#height(b126dc7c1de90089).()) > (m_Hcxx . . $ UIObject#m_H. - m_TextOffYcxx . . $ UIListBox#m_TextOffY. - darrow.heightcxx . . $ UITextItem#height(b126dc7c1de90089).() + 1)) {
683 if (i < (m_NumItemscxx . . $ UIListBox#m_NumItems. - 1)) {
684 m_DownArrowY0cxx . . $ UIListBox#m_DownArrowY0. = m_Hcxx . . $ UIObject#m_H. - m_TextOffYcxx . . $ UIListBox#m_TextOffY. - darrow.heightcxx . . $ UITextItem#height(b126dc7c1de90089).() + 1;
685 m_DownArrowY1cxx . . $ UIListBox#m_DownArrowY1. = m_Hcxx . . $ UIObject#m_H. - m_TextOffYcxx . . $ UIListBox#m_TextOffY.;
686 darrow.drawcxx . . $ UITextItem#draw(84329bcd07240ccf).(m_TextOffXcxx . . $ UIListBox#m_TextOffX., m_DownArrowY0cxx . . $ UIListBox#m_DownArrowY0., IsDisabledcxx . . $ UIGadget#IsDisabled(c9857a73d68e59ba).() ? uiDrawFadedcxx . . $ uiDrawFaded. : uiDrawNormalcxx . . $ uiDrawNormal.);
687 m_ShowDowncxx . . $ UIListBox#m_ShowDown. = true;
688 }
689 break;
690 }
691 } else if ((y + m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->heightcxx . . $ UIItem#height(b126dc7c1de90089).() + 2) > (m_Hcxx . . $ UIObject#m_H. - m_TextOffYcxx . . $ UIListBox#m_TextOffY.)) {
692 break;
693 }
694
695 y += m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->heightcxx . . $ UIItem#height(b126dc7c1de90089).() + 2;
696 }
697
698 if (m_NumItemscxx . . $ UIListBox#m_NumItems.) {
699 if (use_scroll && auto_select) {
700 if (m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. < m_Indexcxx . . $ UIListBox#m_Index.)
701 UIListBoxcxx . . $ UIListBox#::SetSelectedIndexcxx . . $ UIListBox#SetSelectedIndex(d4f767463ce0a6b3).(m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[m_Indexcxx . . $ UIListBox#m_Index.]);
702 if (m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. > i)
703 UIListBoxcxx . . $ UIListBox#::SetSelectedIndexcxx . . $ UIListBox#SetSelectedIndex(d4f767463ce0a6b3).(m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[i]);
704 }
705 }
706
707 m_NumVisibleItemscxx . . $ UIListBox#m_NumVisibleItems. = i - m_Indexcxx . . $ UIListBox#m_Index.;
708
709 ui_ResetTextClipcxx . . $ ui_ResetTextClip(49f6e7a06ebc5aa8).();
710 }
711
712 // behavior when key is pressed.
713 void UIListBoxcxx . . $ UIListBox#::OnKeyDowncxx . . $ UIListBox#OnKeyDown(d4f767463ce0a6b3).(int key) {
714 UIGadgetcxx . . $ UIGadget# *gadget = this;
715
716 if (key == KEY_UPcxx . . $ `ddio/ddio_common.h:318:9`!) {
717 if (m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. > 0) {
718 if (m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. == m_Indexcxx . . $ UIListBox#m_Index.)
719 m_Indexcxx . . $ UIListBox#m_Index.--;
720 m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex.--;
721
722 UIListBoxcxx . . $ UIListBox#::SetInternalSelectedIndexcxx . . $ UIListBox#SetInternalSelectedIndex(d4f767463ce0a6b3).((m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.) ? m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex.] : 0);
723 }
724 } else if (key == KEY_DOWNcxx . . $ `ddio/ddio_common.h:319:9`!) {
725 if (m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. < (m_NumItemscxx . . $ UIListBox#m_NumItems. - 1)) {
726 if (m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. >= (m_Indexcxx . . $ UIListBox#m_Index. + m_NumVisibleItemscxx . . $ UIListBox#m_NumVisibleItems.))
727 m_Indexcxx . . $ UIListBox#m_Index.++;
728 m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex.++;
729 UIListBoxcxx . . $ UIListBox#::SetInternalSelectedIndexcxx . . $ UIListBox#SetInternalSelectedIndex(d4f767463ce0a6b3).((m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.) ? m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex.] : 0);
730 }
731 } else if (key == KEY_PAGEDOWNcxx . . $ `ddio/ddio_common.h:317:9`!) {
732 if (m_Indexcxx . . $ UIListBox#m_Index. < (m_NumItemscxx . . $ UIListBox#m_NumItems. - m_NumVisibleItemscxx . . $ UIListBox#m_NumVisibleItems.))
733 m_Indexcxx . . $ UIListBox#m_Index. = m_Indexcxx . . $ UIListBox#m_Index. + m_NumVisibleItemscxx . . $ UIListBox#m_NumVisibleItems.;
734 if (m_Indexcxx . . $ UIListBox#m_Index. > (m_NumItemscxx . . $ UIListBox#m_NumItems. - m_NumVisibleItemscxx . . $ UIListBox#m_NumVisibleItems.))
735 m_Indexcxx . . $ UIListBox#m_Index. = m_NumItemscxx . . $ UIListBox#m_NumItems. - m_NumVisibleItemscxx . . $ UIListBox#m_NumVisibleItems.;
736 m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. = m_Indexcxx . . $ UIListBox#m_Index.;
737 UIListBoxcxx . . $ UIListBox#::SetInternalSelectedIndexcxx . . $ UIListBox#SetInternalSelectedIndex(d4f767463ce0a6b3).((m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.) ? m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex.] : 0);
738 } else if (key == KEY_PAGEUPcxx . . $ `ddio/ddio_common.h:314:9`!) {
739 m_Indexcxx . . $ UIListBox#m_Index. = m_Indexcxx . . $ UIListBox#m_Index. - m_NumVisibleItemscxx . . $ UIListBox#m_NumVisibleItems.;
740 if (m_Indexcxx . . $ UIListBox#m_Index. < 0)
741 m_Indexcxx . . $ UIListBox#m_Index. = 0;
742 m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex. = m_Indexcxx . . $ UIListBox#m_Index.;
743
744 UIListBoxcxx . . $ UIListBox#::SetInternalSelectedIndexcxx . . $ UIListBox#SetInternalSelectedIndex(d4f767463ce0a6b3).((m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.) ? m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[m_SelectedIndexcxx . . $ UIListBox#m_SelectedIndex.] : 0);
745 }
746 }
747
748 // behavior when key is released.
749 void UIListBoxcxx . . $ UIListBox#::OnKeyUpcxx . . $ UIListBox#OnKeyUp(d4f767463ce0a6b3).(int key) {}
750
751 // behavior when mouse button is pressed.
752 void UIListBoxcxx . . $ UIListBox#::OnMouseBtnDowncxx . . $ UIListBox#OnMouseBtnDown(d4f767463ce0a6b3).(int btn) {
753 // One day, this system needs a complete rewrite, for all this stuff is a HACK!!!!
754 if (btn == UILMSEBTNcxx . . $ `ui/uisys.h:36:9`!) {
755 if (m_MouseStatecxx . . $ UIListBox#m_MouseState. == 1 || m_MouseStatecxx . . $ UIListBox#m_MouseState. == 2) { // single click pass or double clicking
756 // handle first slow delay scrolling (like keyboard input)
757 if ((m_ClickTimecxx . . $ UIListBox#m_ClickTime. + KEYDOWN_FIRST_DELAYcxx . . $ `ui/ui.h:753:9`!) > UI_TIMEcxx . . $ UI_TIME(9b8c9e39889c762c).()) {
758 // mprintf(0, "old=%.3f cur=%.3f\n", m_ClickTime, UI_TIME());
759 return;
760 } else
761 m_MouseStatecxx . . $ UIListBox#m_MouseState. = 3;
762 } else if (m_MouseStatecxx . . $ UIListBox#m_MouseState. == 3) {
763 // handle repeat scrolling (note this is if the user has scrolled once already.
764 if ((m_ClickTimecxx . . $ UIListBox#m_ClickTime. + KEYDOWN_REPEAT_DELAYcxx . . $ `ui/ui.h:754:9`!) > UI_TIMEcxx . . $ UI_TIME(9b8c9e39889c762c).()) {
765 // mprintf(0, "old=%.3f cur=%.3f\n", m_ClickTime, UI_TIME());
766 return;
767 }
768 } else if (m_MouseStatecxx . . $ UIListBox#m_MouseState. == 0) {
769 m_MouseStatecxx . . $ UIListBox#m_MouseState. = 1;
770 m_MouseXcxx . . $ UIListBox#m_MouseX. = SCREEN_TO_GAD_Xcxx . . $ SCREEN_TO_GAD_X(dafe5a5d85eeac89).(this, UI_inputcxx . . $ UI_input..mxcxx . . $ tUIInput#mx.);
771 m_MouseYcxx . . $ UIListBox#m_MouseY. = SCREEN_TO_GAD_Ycxx . . $ SCREEN_TO_GAD_Y(dafe5a5d85eeac89).(this, UI_inputcxx . . $ UI_input..mycxx . . $ tUIInput#my.);
772
773 MseCheckSelectcxx . . $ UIListBox#MseCheckSelect(cf9ef193275fa6d8).(m_MouseXcxx . . $ UIListBox#m_MouseX., m_MouseYcxx . . $ UIListBox#m_MouseY.);
774
775 if (UI_TIMEcxx . . $ UI_TIME(9b8c9e39889c762c).() < (m_ClickTimecxx . . $ UIListBox#m_ClickTime. + UI_DBLCLICK_DELAYcxx . . $ `ui/uisys.h:40:9`!)) {
776 if (abscxx . . $ abs(a1851578aea3f541).(m_LastMseXcxx . . $ UIListBox#m_LastMseX. - m_MouseXcxx . . $ UIListBox#m_MouseX.) < UI_DBLCLICK_MSEDELTAcxx . . $ `ui/uisys.h:41:9`! && abscxx . . $ abs(a1851578aea3f541).(m_LastMseYcxx . . $ UIListBox#m_LastMseY. - m_MouseYcxx . . $ UIListBox#m_MouseY.) < UI_DBLCLICK_MSEDELTAcxx . . $ `ui/uisys.h:41:9`!) {
777
778 if (MseCheckSelectcxx . . $ UIListBox#MseCheckSelect(cf9ef193275fa6d8).(m_MouseXcxx . . $ UIListBox#m_MouseX., m_MouseYcxx . . $ UIListBox#m_MouseY.))
779 OnSelectcxx . . $ UIListBox#OnSelect(49f6e7a06ebc5aa8).();
780 m_MouseStatecxx . . $ UIListBox#m_MouseState. = 2;
781 }
782 }
783 LOCK_FOCUScxx . . $ `ui/uisys.h:107:9`!(this);
784 }
785
786 m_ClickTimecxx . . $ UIListBox#m_ClickTime. = UI_TIMEcxx . . $ UI_TIME(9b8c9e39889c762c).(); // use for scroll timing, this should be reset on button release
787 // mprintf(0, "new=%.3f\n", m_ClickTime);
788
789 // code here should allow for continuous scrolling on mouse down.
790 // we need to add timing so scrolling isn't do damn quick.
791 m_LastMseXcxx . . $ UIListBox#m_LastMseX. = m_MouseXcxx . . $ UIListBox#m_MouseX.;
792 m_LastMseYcxx . . $ UIListBox#m_LastMseY. = m_MouseYcxx . . $ UIListBox#m_MouseY.;
793
794 if (m_ShowUpcxx . . $ UIListBox#m_ShowUp. && m_MouseYcxx . . $ UIListBox#m_MouseY. >= m_UpArrowY0cxx . . $ UIListBox#m_UpArrowY0. && m_MouseYcxx . . $ UIListBox#m_MouseY. <= m_UpArrowY1cxx . . $ UIListBox#m_UpArrowY1.) {
795 if (m_MouseXcxx . . $ UIListBox#m_MouseX. < (m_TextOffXcxx . . $ UIListBox#m_TextOffX. + m_ArrowWidthcxx . . $ UIListBox#m_ArrowWidth.)) {
796 if (m_Indexcxx . . $ UIListBox#m_Index. > 0)
797 m_Indexcxx . . $ UIListBox#m_Index.--;
798 }
799 } else if (m_ShowDowncxx . . $ UIListBox#m_ShowDown. && m_MouseYcxx . . $ UIListBox#m_MouseY. >= m_DownArrowY0cxx . . $ UIListBox#m_DownArrowY0. && m_MouseYcxx . . $ UIListBox#m_MouseY. <= m_DownArrowY1cxx . . $ UIListBox#m_DownArrowY1.) {
800 if (m_MouseXcxx . . $ UIListBox#m_MouseX. < (m_TextOffXcxx . . $ UIListBox#m_TextOffX. + m_ArrowWidthcxx . . $ UIListBox#m_ArrowWidth.)) {
801 if (m_Indexcxx . . $ UIListBox#m_Index. < (m_NumItemscxx . . $ UIListBox#m_NumItems. - m_NumVisibleItemscxx . . $ UIListBox#m_NumVisibleItems.))
802 m_Indexcxx . . $ UIListBox#m_Index.++;
803 }
804 }
805 }
806 }
807
808 // behavior when mouse button is released.
809 void UIListBoxcxx . . $ UIListBox#::OnMouseBtnUpcxx . . $ UIListBox#OnMouseBtnUp(d4f767463ce0a6b3).(int btn) {
810 if (btn == UILMSEBTNcxx . . $ `ui/uisys.h:36:9`!) {
811 if (m_MouseStatecxx . . $ UIListBox#m_MouseState. == 0)
812 return;
813 if (m_MouseStatecxx . . $ UIListBox#m_MouseState. == 2) // double clicked.
814 m_ClickTimecxx . . $ UIListBox#m_ClickTime. = -2.0f;
815 else if (m_MouseStatecxx . . $ UIListBox#m_MouseState. == 1 || m_MouseStatecxx . . $ UIListBox#m_MouseState. == 3) // single clicked or prolonged single click.
816 m_ClickTimecxx . . $ UIListBox#m_ClickTime. = UI_TIMEcxx . . $ UI_TIME(9b8c9e39889c762c).();
817 m_MouseStatecxx . . $ UIListBox#m_MouseState. = 0;
818 UNLOCK_FOCUScxx . . $ `ui/uisys.h:109:9`!(this);
819 }
820 }
821
822 void UIListBoxcxx . . $ UIListBox#::OnSelectcxx . . $ UIListBox#OnSelect(49f6e7a06ebc5aa8).() { UIGadgetcxx . . $ UIGadget#::OnSelectcxx . . $ UIGadget#OnSelect(49f6e7a06ebc5aa8).(); }
823
824 void UIListBoxcxx . . $ UIListBox#::SetSelectedColorcxx . . $ UIListBox#SetSelectedColor(cb2f890c2fdad230).(ddgr_colorcxx . . $ ddgr_color# col) { m_SelectColorcxx . . $ UIListBox#m_SelectColor. = col; }
825
826 void UIListBoxcxx . . $ UIListBox#::SetHiliteColorcxx . . $ UIListBox#SetHiliteColor(cb2f890c2fdad230).(ddgr_colorcxx . . $ ddgr_color# col) { m_HiliteColorcxx . . $ UIListBox#m_HiliteColor. = col; }
827
828 // override: behavior when gadget loses input focus.
829 void UIListBoxcxx . . $ UIListBox#::OnLostFocuscxx . . $ UIListBox#OnLostFocus(49f6e7a06ebc5aa8).() {
830 m_Alphacxx . . $ UIListBox#m_Alpha. = 192;
831
832 UIGadgetcxx . . $ UIGadget#::OnLostFocuscxx . . $ UIGadget#OnLostFocus(49f6e7a06ebc5aa8).();
833 }
834
835 // override: behavior when gadget gains input focus.
836 void UIListBoxcxx . . $ UIListBox#::OnGainFocuscxx . . $ UIListBox#OnGainFocus(49f6e7a06ebc5aa8).() {
837 m_Alphacxx . . $ UIListBox#m_Alpha. = 255;
838 UIGadgetcxx . . $ UIGadget#::OnGainFocuscxx . . $ UIGadget#OnGainFocus(49f6e7a06ebc5aa8).();
839 }
840
841 // override: behavior when gadget is processed
842 void UIListBoxcxx . . $ UIListBox#::OnUserProcesscxx . . $ UIListBox#OnUserProcess(49f6e7a06ebc5aa8).() {
843 // if mouse is outside listbox, unlock the focus on this listbox.
844 // if (this->IsLocked()) {
845 // if (!m_Wnd->HasKeyFocus() && !PT_IN_GADGET(UIGadget::m_Wnd, this, UI_input.mx, UI_input.my)) {
846 // UNLOCK_FOCUS(this);
847 // this->LostFocus();
848 // }
849 // }
850 }
851
852 // check if x and y selection hits a selected item.
853 bool UIListBoxcxx . . $ UIListBox#::MseCheckSelectcxx . . $ UIListBox#MseCheckSelect(cf9ef193275fa6d8).(int x, int y) {
854 int i, ty;
855 bool use_scroll = !(m_Flagscxx . . $ UIGadget#m_Flags. & UILB_NOSCROLLcxx . . $ `ui/ui.h:354:9`!);
856
857 if (!m_NumItemscxx . . $ UIListBox#m_NumItems.)
858 return false;
859
860 if (m_ShowUpcxx . . $ UIListBox#m_ShowUp.)
861 ty = m_UpArrowY0cxx . . $ UIListBox#m_UpArrowY0.;
862 else
863 ty = m_TextOffYcxx . . $ UIListBox#m_TextOffY.;
864
865 for (i = m_Indexcxx . . $ UIListBox#m_Index.; i < m_NumItemscxx . . $ UIListBox#m_NumItems.; i++) {
866 // check if mouse down event occurred within this item.
867 if (y >= ty && y < (ty + m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->heightcxx . . $ UIItem#height(b126dc7c1de90089).() + 2)) {
868 if (x > (m_ArrowWidthcxx . . $ UIListBox#m_ArrowWidth. + m_TextOffXcxx . . $ UIListBox#m_TextOffX.)) {
869 UIListBoxcxx . . $ UIListBox#::SetInternalSelectedIndexcxx . . $ UIListBox#SetInternalSelectedIndex(d4f767463ce0a6b3).((m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.) ? m_Real2Virtcxx . . $ UIListBox#m_Real2Virt.[i] : 0);
870 return true;
871 }
872 }
873
874 if (m_ShowDowncxx . . $ UIListBox#m_ShowDown. && (ty + m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->heightcxx . . $ UIItem#height(b126dc7c1de90089).()) > m_DownArrowY1cxx . . $ UIListBox#m_DownArrowY1.)
875 return false;
876 else if ((ty + m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->heightcxx . . $ UIItem#height(b126dc7c1de90089).()) > (m_Hcxx . . $ UIObject#m_H. - m_TextOffYcxx . . $ UIListBox#m_TextOffY.))
877 return false;
878
879 ty += m_ItemListcxx . . $ UIListBox#m_ItemList.[i]->heightcxx . . $ UIItem#height(b126dc7c1de90089).() + 2;
880 }
881
882 return false;
883 }