-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathform.nvgt
4190 lines (4182 loc) · 128 KB
/
form.nvgt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* form.nvgt - audio form originally taken from bgt, but now heavily modified
*
* NVGT - NonVisual Gaming Toolkit
* Copyright (c) 2022-2024 Sam Tupy
* https://nvgt.gg
* original form.bgt Copyright (C) 2010-2014 Blastbay Studios
* This software is provided "as-is", without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#include "speech.nvgt"
/* modified by Sam Tupy:
audioform_input_disable_ralt
added search text functionality
control+arrows now moves by more than just space
added get_line_number, get_line_column, and set_line functions
added the ct_form control type
added the ct_keyboard_area control type
changed some text field cosmetics
added multiline_enter as an optional arg to create_input_box to make shift or control+enter insert a new line while enter still activates the default control
adds focus_silently and focus_interrupt functions
adds set_default_controls function
list items can now have ID strings apart from the item names (add_list_item extra param, get_list_item_id, edit_list_item_id)
shortcut announcement now respects the separate_attributes parameter
fixed absolutely critical multiline bug that somehow made it into BGT's release
pasting text now moves cursor to end of pasted text
added set_keyboard_echo function
added set_default_keyboard_echo function
finished keyboard echo modes
added complete keyboard repeating
added multi-letter-navigation in lists with a function called set_list_multinavigation that lets you enable or disable it for both letters and numbers
fixed and changed anouncement of checkboxes
deleting text now calls input_box_speak with ignore_echo_flag set to true
delete_speech_text now empty by default and no space is added to text string if this is true (if you press backspace or delete you know your deleting)
fixed selections speaking the contents of password fields
pasting in text fields now just says text pasted instead of anouncing what you have pasted, both to decrease annoyance and to make password fields secure
create_list now has a repeat_boundary_items argument, which if true causes pressing up or down arrows on list boundaries to repeat the first or last item depending
set_list_position now has speak_new_item argument (false by default)
edit_list_item had taken code from add_list_item thus not allowing item editing if the list was full and also allowing a runtime error if attempting to edit an item 1 greater than the list length, these bugs have been fixed
added the ct_slider control type, create_slider, get_slider, set_slider, get_slider_text_value, set_slider_text_value, clear_slider_text_values
added prespeech callback
added event callback
*/
//constants
enum clipboard_flags
{
clipboard_flag_copy = 1 << 0,
clipboard_flag_cut = 1 << 1,
clipboard_flag_paste = 1 << 2
}
enum control_types {
ct_button = 0,
ct_input,
ct_checkbox,
ct_progress,
ct_status_bar,
ct_list,
ct_slider,
ct_form,
ct_keyboard_area,
ct_link
}
//form_errors
enum audioform_errorcodes {
form_error_none = 0,
form_error_invalid_index,
form_error_invalid_control,
form_error_invalid_value,
form_error_invalid_operation,
form_error_no_window,
form_error_window_full,
form_error_text_too_long,
form_error_list_empty,
form_error_list_full,
form_error_invalid_list_index,
form_error_control_invisible,
form_error_no_controls_visible
}
//text entry speech flags
enum text_entry_speech_flags {
textflag_none = 0,
textflag_characters,
textflag_words,
textflag_characters_words
}
//Text edit modes
enum text_edit_mode_constants {
edit_mode_replace = 0,
edit_mode_trim_to_length,
edit_mode_append_to_end
}
//types of update events that can be received by controls
enum control_event_type {
event_none = 0,
event_focus,
event_list_cursor,
event_text_cursor,
event_button,
event_checkbox,
event_slider
}
//characters that should be considered word boundaries.
string audioform_word_separators = "_ .,!\\\"/[{()}]=\n";
//prespeech callback, if set the given function will be called right before the form speaks.
funcdef void prespeech_callback(audio_form@ f);
// Background callback, this method is fired at the top of the monitor function and can return false to abort the forms monitor logic during that iteration. It can be useful when creating UI extension libraries that need to insert logic into any form in an application without modifying every loop that invoques form.monitor in the target application.
funcdef bool form_background_callback(audio_form@ f);
//control event callback
funcdef int on_control_event_callback(audio_form@ f, int c, control_event_type event, dictionary@ args);
//can make this a member of the audio form class as soon as even one person suggests seriously wanting to change on a form by form basis I guess
bool audioform_input_disable_ralt = true;
int audioform_keyboard_echo = textflag_characters;
form_background_callback@ audioform_default_background_callback = null;
//main window class
class audio_form {
bool active;
bool speak_control_attributes_separately;
int subform_control_index = -1;
on_control_event_callback@ event_callback = null;
form_background_callback@ background_callback = @audioform_default_background_callback;
utility_form@ utility_form = null;
dictionary utility_form_data;
//constructor
audio_form() {
reset();
}
void create_window() {
create_window("", false, false, true);
}
void create_window(string window_title, bool change_screen_title = true, bool say_dialog = true, bool silent = false) {
form_error = 0;
if (!active)
get_characters();
active = true;
if (!silent && change_screen_title && window_title != "")
show_window(window_title);
/*if(@ui_speech==null)
{
tts_voice temp_voice;
@ui_speech=temp_voice;
}*/
if (window_title == "" || silent)
return;
if (speak_control_attributes_separately) {
speak(window_title, true);
if (say_dialog)
speak("Dialog", false);
} else {
if (say_dialog)
speak(window_title + " Dialog", true);
else
speak(window_title, true);
}
}
bool set_checkbox_mark(int control_index, bool checked) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (c_form[control_index].type != ct_checkbox) {
form_error = form_error_invalid_control;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
c_form[control_index].checked = checked;
return true;
}
bool set_custom_type(int control_index, string custom_type)
{
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_control;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
if (custom_type.empty()) {
form_error = form_error_invalid_value;
return false;
}
c_form[control_index].custom_type = custom_type;
return true;
}
string get_custom_type(int control_index) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return "";
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return "";
}
return c_form[control_index].custom_type;
}
bool has_custom_type(int control_index) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
return !c_form[control_index].custom_type.empty();
}
bool set_subform(int control_index, audio_form@ f) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (c_form[control_index].type != ct_form) {
form_error = form_error_invalid_control;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
@c_form[control_index].subform = @f;
if (@f != null) {
f.subform = true;
f.subform_control_index = control_index;
}
return true;
}
bool set_output_mode(int speech_output, bool progress_bars_beep = false) {
form_error = 0;
if ((speech_output < 0) || (speech_output > 4))
return false;
this.speech_output = speech_output;
for (int counter = 0; counter < c_form.length(); counter++) {
c_form[counter].speech_output = speech_output;
c_form[counter].beeping_progress = progress_bars_beep;
if (c_form[counter].beeping_progress) {
}
}
return true;
}
int create_input_box(string caption, string default_text = "", string password_mask = "", int maximum_length = 0, bool read_only = false, bool multiline = false, bool multiline_enter = true) {
form_error = 0;
if (active_controls >= 50) {
form_error = form_error_window_full;
return -1;
}
control_counter++;
active_controls++;
c_form.resize(control_counter + 1);
c_form[control_counter].type = ct_input;
@c_form[control_counter].event_callback = event_callback;
c_form[control_counter].hotkey = shortcut(caption);
c_form[control_counter].hotkey_letter = shortcut_letter(caption);
c_form[control_counter].caption = caption.replace("&", "", true);
c_form[control_counter].visible = true;
c_form[control_counter].enabled = true;
c_form[control_counter].enable_delete = true;
set_clipboard_flags(control_counter, true, true, true);
c_form[control_counter].speech_output = speech_output;
if ((maximum_length > 0) && (default_text.length() > maximum_length)) {
default_text = default_text.substr(0, maximum_length);
form_error = form_error_text_too_long;
}
c_form[control_counter].text = default_text;
c_form[control_counter].cursor = 0;
c_form[control_counter].sel_start = -1;
c_form[control_counter].sel_end = -1;
c_form[control_counter].max_length = maximum_length;
c_form[control_counter].password_mask = password_mask.substr(0, 1);
c_form[control_counter].read_only = read_only;
c_form[control_counter].multiline = multiline;
c_form[control_counter].multiline_enter = multiline_enter;
c_form[control_counter].echo_flag = default_echo_flag;
@c_form[control_counter].ui_speech = ui_speech;
return control_counter;
}
int create_list(string caption, int maximum_items = 0, bool multiselect = false, bool repeat_boundary_items = false) {
form_error = 0;
if (active_controls >= 50) {
form_error = form_error_window_full;
return -1;
}
control_counter++;
active_controls++;
c_form.resize(control_counter + 1);
c_form[control_counter].type = ct_list;
@c_form[control_counter].event_callback = event_callback;
c_form[control_counter].hotkey = shortcut(caption);
c_form[control_counter].hotkey_letter = shortcut_letter(caption);
c_form[control_counter].caption = caption.replace("&", "", true);
c_form[control_counter].visible = true;
c_form[control_counter].enabled = true;
c_form[control_counter].max_length = maximum_items;
c_form[control_counter].list_multiselect = multiselect;
c_form[control_counter].list_repeat_boundary_items = repeat_boundary_items;
c_form[control_counter].speech_output = speech_output;
@c_form[control_counter].ui_speech = ui_speech;
return control_counter;
}
int create_tab_panel(string caption, int maximum_items = 0, bool repeat_boundary_items = false) {
form_error = 0;
if (active_controls >= 50) {
form_error = form_error_window_full;
return -1;
}
control_counter++;
active_controls++;
c_form.resize(control_counter + 1);
c_form[control_counter].type = ct_list;
@c_form[control_counter].event_callback = event_callback;
c_form[control_counter].hotkey = shortcut(caption);
c_form[control_counter].hotkey_letter = shortcut_letter(caption);
c_form[control_counter].caption = caption.replace("&", "", true);
c_form[control_counter].visible = true;
c_form[control_counter].enabled = true;
c_form[control_counter].max_length = maximum_items;
c_form[control_counter].list_multiselect = false;
c_form[control_counter].list_repeat_boundary_items = repeat_boundary_items;
c_form[control_counter].list_is_tab_panel = true;
c_form[control_counter].speech_output = speech_output;
@c_form[control_counter].ui_speech = ui_speech;
return control_counter;
}
int create_button(string caption, bool primary = false, bool cancel = false, bool overwrite = true) {
form_error = 0;
if (active_controls >= 50) {
form_error = form_error_window_full;
return -1;
}
control_counter++;
active_controls++;
c_form.resize(control_counter + 1);
c_form[control_counter].type = ct_button;
@c_form[control_counter].event_callback = event_callback;
c_form[control_counter].hotkey = shortcut(caption);
c_form[control_counter].hotkey_letter = shortcut_letter(caption);
c_form[control_counter].caption = caption.replace("&", "", true);
c_form[control_counter].visible = true;
c_form[control_counter].enabled = true;
c_form[control_counter].speech_output = speech_output;
@c_form[control_counter].ui_speech = ui_speech;
set_button_attributes(control_counter, primary, cancel, overwrite);
return control_counter;
}
int create_progress_bar(string caption, int speak_interval = 5, bool speak_global = true) {
form_error = 0;
if (active_controls >= 50) {
form_error = form_error_window_full;
return -1;
}
control_counter++;
active_controls++;
c_form.resize(control_counter + 1);
c_form[control_counter].type = ct_progress;
@c_form[control_counter].event_callback = event_callback;
c_form[control_counter].hotkey = shortcut(caption);
c_form[control_counter].hotkey_letter = shortcut_letter(caption);
c_form[control_counter].caption = caption.replace("&", "", true);
c_form[control_counter].visible = true;
c_form[control_counter].enabled = true;
c_form[control_counter].speak_interval = speak_interval * 1000;
c_form[control_counter].speak_global = check_globals(speak_global);
c_form[control_counter].speech_output = speech_output;
@c_form[control_counter].ui_speech = ui_speech;
return control_counter;
}
int create_slider(string caption, double default_value = 50, double minimum_value = 0, double maximum_value = 100, string text = "", double step_size = 1) {
form_error = 0;
if (active_controls >= 50) {
form_error = form_error_window_full;
return -1;
}
control_counter++;
active_controls++;
c_form.resize(control_counter + 1);
c_form[control_counter].type = ct_slider;
@c_form[control_counter].event_callback = event_callback;
c_form[control_counter].hotkey = shortcut(caption);
c_form[control_counter].hotkey_letter = shortcut_letter(caption);
c_form[control_counter].caption = caption.replace("&", "", true);
c_form[control_counter].visible = true;
c_form[control_counter].enabled = true;
c_form[control_counter].slider_value = default_value;
c_form[control_counter].slider_minimum_value = minimum_value;
c_form[control_counter].slider_maximum_value = maximum_value;
c_form[control_counter].slider_step_size = step_size;
c_form[control_counter].text = text;
c_form[control_counter].speech_output = speech_output;
@c_form[control_counter].ui_speech = ui_speech;
return control_counter;
}
int create_status_bar(string caption, string text) {
form_error = 0;
if (active_controls >= 50) {
form_error = form_error_window_full;
return -1;
}
control_counter++;
active_controls++;
c_form.resize(control_counter + 1);
c_form[control_counter].type = ct_status_bar;
@c_form[control_counter].event_callback = event_callback;
c_form[control_counter].hotkey = shortcut(caption);
c_form[control_counter].hotkey_letter = shortcut_letter(caption);
c_form[control_counter].caption = caption.replace("&", "", true);
c_form[control_counter].visible = true;
c_form[control_counter].enabled = true;
c_form[control_counter].text = text;
c_form[control_counter].speech_output = speech_output;
@c_form[control_counter].ui_speech = ui_speech;
return control_counter;
}
int create_keyboard_area(string caption) {
form_error = 0;
if (active_controls >= 50) {
form_error = form_error_window_full;
return -1;
}
control_counter++;
active_controls++;
c_form.resize(control_counter + 1);
c_form[control_counter].type = ct_keyboard_area;
@c_form[control_counter].event_callback = event_callback;
c_form[control_counter].hotkey = shortcut(caption);
c_form[control_counter].hotkey_letter = shortcut_letter(caption);
c_form[control_counter].caption = caption.replace("&", "", true);
c_form[control_counter].visible = true;
c_form[control_counter].enabled = true;
c_form[control_counter].speech_output = speech_output;
@c_form[control_counter].ui_speech = ui_speech;
return control_counter;
}
int create_subform(string caption, audio_form@ f) {
if (@f != null) f.subform = true;
form_error = 0;
if (active_controls >= 50) {
form_error = form_error_window_full;
return -1;
}
control_counter++;
active_controls++;
c_form.resize(control_counter + 1);
c_form[control_counter].type = ct_form;
@c_form[control_counter].event_callback = event_callback;
c_form[control_counter].hotkey = shortcut(caption);
c_form[control_counter].hotkey_letter = shortcut_letter(caption);
c_form[control_counter].caption = caption.replace("&", "", true);
c_form[control_counter].visible = true;
c_form[control_counter].enabled = true;
c_form[control_counter].speech_output = speech_output;
@c_form[control_counter].ui_speech = ui_speech;
@c_form[control_counter].subform = f;
if (@f != null) f.subform_control_index = control_counter;
return control_counter;
}
int create_checkbox(string caption, bool initial_value = false, bool read_only = false) {
form_error = 0;
if (active_controls >= 50) {
form_error = form_error_window_full;
return -1;
}
control_counter++;
active_controls++;
c_form.resize(control_counter + 1);
c_form[control_counter].type = ct_checkbox;
@c_form[control_counter].event_callback = event_callback;
c_form[control_counter].hotkey = shortcut(caption);
c_form[control_counter].hotkey_letter = shortcut_letter(caption);
c_form[control_counter].caption = caption.replace("&", "", true);
c_form[control_counter].visible = true;
c_form[control_counter].enabled = true;
c_form[control_counter].checked = initial_value;
c_form[control_counter].read_only = read_only;
c_form[control_counter].speech_output = speech_output;
@c_form[control_counter].ui_speech = ui_speech;
return control_counter;
}
int create_link(string caption, string url) {
form_error = 0;
if (active_controls >= 50) {
form_error = form_error_window_full;
return -1;
}
control_counter++;
active_controls++;
c_form.resize(control_counter + 1);
c_form[control_counter].type = ct_link;
@c_form[control_counter].event_callback = event_callback;
c_form[control_counter].hotkey = shortcut(caption);
c_form[control_counter].hotkey_letter = shortcut_letter(caption);
c_form[control_counter].caption = caption.replace("&", "", true);
c_form[control_counter].link_url = url;
c_form[control_counter].visible = true;
c_form[control_counter].enabled = true;
c_form[control_counter].speech_output = speech_output;
@c_form[control_counter].ui_speech = ui_speech;
return control_counter;
}
bool activate_progress_timer(int control_index) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (c_form[control_index].type != ct_progress) {
form_error = form_error_invalid_control;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
if (c_form[control_index].speak_interval == 0) {
form_error = form_error_invalid_value;
return false;
}
if (c_form[control_index].progress_time.running == true) {
form_error = form_error_invalid_operation;
return false;
}
c_form[control_index].progress_time.resume();
return true;
}
bool pause_progress_timer(int control_index) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (c_form[control_index].type != ct_progress) {
form_error = form_error_invalid_control;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
if (!c_form[control_index].progress_time.running) {
form_error = form_error_invalid_operation;
return false;
}
c_form[control_index].progress_time.pause();
return true;
}
bool delete_control(int control_index) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_control;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
c_form[control_index].active = false;
if (c_form[control_index].type == ct_progress) {
}
active_controls--;
control_focus = -1;
return true;
}
int monitor() {
if (@background_callback != null and background_callback(this) and total_keys_down() < 1) return 0;
if (@utility_form != null) {
utility_form.monitor();
return 0;
}
int start = control_focus;
int defaults = get_default_button();
int cancels = get_cancel_button();
int focused = get_current_focus();
form_error = 0;
if ((key_pressed(KEY_LCTRL)) || (key_pressed(KEY_RCTRL)))
stop_speech();
if (!active) {
form_error = form_error_no_window;
return 0;
}
int autotab = 0;
if (focused > -1 && focused <= control_counter && c_form[focused].type == ct_form && @c_form[focused].subform != null && c_form[focused].subform.get_control_count() > 0)
autotab = c_form[focused].subform.monitor();
if (key_repeating(KEY_TAB) || autotab != 0 && autotab < 2) {
if ((control_counter < 0) || (key_down(KEY_LALT)) || (key_down(KEY_LGUI)) || (key_down(KEY_RALT)) || (key_down(KEY_RGUI)))
return 0;
if ((control_counter == 0) && (control_focus == 0))
return autotab;
if ((key_down(KEY_LSHIFT)) || (key_down(KEY_RSHIFT)) || autotab == -1) {
control_focus--;
if (control_focus < 0) {
if (subform) {
focus_silently(0);
return -1;
}
control_focus = control_counter;
}
while ((c_form[control_focus].visible == false) || (c_form[control_focus].active == false) || (@c_form[control_focus].subform != null && c_form[control_focus].subform.get_control_count() < 1)) {
control_focus--;
if (control_focus < 0) {
if (subform) {
focus_silently(0);
return -1;
}
control_focus = control_counter;
}
if (control_focus == start) {
form_error = form_error_no_controls_visible;
return -1;
}
}
if (c_form[control_focus].type == ct_form and @c_form[control_focus].subform != null)
c_form[control_focus].subform.focus_silently(c_form[control_focus].subform.get_control_count() - 1);
} else {
control_focus++;
if (control_focus > control_counter) {
if (subform) {
focus_silently(0);
return 1;
}
control_focus = 0;
}
while ((c_form[control_focus].visible == false) || (c_form[control_focus].active == false) || (@c_form[control_focus].subform != null && c_form[control_focus].subform.get_control_count() < 1)) {
control_focus++;
if (control_focus > control_counter) {
if (subform) {
focus_silently(0);
return 1;
}
control_focus = 0;
}
if (control_focus == start) {
form_error = form_error_no_controls_visible;
return 1;
}
if (c_form[control_focus].type == ct_form and @c_form[control_focus].subform != null)
c_form[control_focus].subform.focus_silently(0);
}
}
focus(control_focus, true);
}
if ((cancels > -1) && (key_repeating(KEY_ESCAPE) || key_released(KEY_AC_BACK))) {
stop_speech();
c_form[cancels].pressed = true;
if (subform)
return 2;
}
if ((focused < 0 || c_form[focused].type != ct_keyboard_area) && (focused < 0 || ((!c_form[focused].multiline_enter || !c_form[focused].multiline) && c_form[focused].type == ct_input || c_form[focused].type == ct_button || c_form[focused].type == ct_list) && key_up(KEY_LCTRL) && key_up(KEY_RCTRL) && key_up(KEY_LSHIFT) && key_up(KEY_RSHIFT)) && (key_pressed(KEY_RETURN) || key_pressed(KEY_NUMPAD_ENTER) || (autotab == 3))) {
stop_speech();
if ((defaults == -1) && (focused > -1)) {
if (c_form[focused].type == ct_button || c_form[focused].type == ct_link)
c_form[focused].pressed = true;
else if (subform)
return 3;
}
if (defaults > -1) {
if (focused == -1)
c_form[defaults].pressed = true;
if (focused > -1) {
if ((c_form[focused].type != ct_button) && ((c_form[focused].type != ct_input) || (!c_form[focused].multiline || !c_form[focused].multiline_enter))) {
c_form[defaults].pressed = true;
if (subform)
return 2;
}
if (c_form[focused].type == ct_button)
c_form[focused].pressed = true;
}
}
}
check_shortcuts();
check_speech_mode();
if (control_focus == -1)
return 0;
check(control_focus);
return 0;
}
bool focus(int control_id) {
return focus(control_id, false);
}
bool focus_interrupt(int control_id) {
return focus(control_id, true);
}
bool focus_silently(int control_id) {
return focus(control_id, false, true);
}
bool is_disallowed_char(int control_index, string char, bool search_all = true) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
return c_form[control_index].is_disallowed_char(char, search_all);
}
bool is_visible(int control_index) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
return c_form[control_index].visible;
}
bool is_enabled(int control_index) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
return c_form[control_index].enabled;
}
bool is_read_only(int control_index) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (c_form[control_index].type != ct_input && c_form[control_index].type != ct_checkbox) {
form_error = form_error_invalid_control;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
return c_form[control_index].read_only;
}
bool is_multiline(int control_index) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (c_form[control_index].type != ct_input) {
form_error = form_error_invalid_control;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
return c_form[control_index].multiline;
}
bool is_pressed(int control_index) {
bool temp;
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (c_form[control_index].type != ct_button) {
form_error = form_error_invalid_control;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
temp = c_form[control_index].pressed;
c_form[control_index].pressed = false;
return temp;
}
bool is_checked(int control_index) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (c_form[control_index].type != ct_checkbox) {
form_error = form_error_invalid_control;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
return c_form[control_index].checked;
}
bool add_list_item(int control_index, const string& in option, int position = -1, bool selected = false, bool focus_if_first = true) {
return add_list_item(control_index, option, "", position, selected, focus_if_first);
}
bool add_list_item(int control_index, const string& in option, string id, int position = -1, bool selected = false, bool focus_if_first = true) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (c_form[control_index].type != ct_list) {
form_error = form_error_invalid_control;
return false;
}
if ((c_form[control_index].max_length > 0) && (c_form[control_index].max_length == c_form[control_index].list.length())) {
form_error = form_error_list_full;
return false;
}
if (position > c_form[control_index].list_length + 1) {
form_error = form_error_invalid_list_index;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
c_form[control_index].list_length++;
if ((position < 0) || (position == c_form[control_index].list_length + 1)) {
c_form[control_index].list.resize(c_form[control_index].list.length() + 1);
c_form[control_index].list[c_form[control_index].list_length].item = option;
c_form[control_index].list[c_form[control_index].list_length].id = id;
if (c_form[control_index].list_multiselect)
c_form[control_index].list[c_form[control_index].list_length].checked = selected;
} else {
c_form[control_index].list.insert_at(position, list_item());
c_form[control_index].list[position].item = option;
c_form[control_index].list[position].id = id;
if (c_form[control_index].list_multiselect)
c_form[control_index].list[position].checked = selected;
}
if (focus_if_first && c_form[control_index].list.length() == 1)
c_form[control_index].list_position = 0;
return true;
}
bool edit_list_item(int control_index, string new_option, int position) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (c_form[control_index].type != ct_list) {
form_error = form_error_invalid_control;
return false;
}
if (position > c_form[control_index].list_length) {
form_error = form_error_invalid_list_index;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
c_form[control_index].list[position].item = new_option;
return true;
}
bool edit_list_item_id(int control_index, string new_id, int position) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (c_form[control_index].type != ct_list) {
form_error = form_error_invalid_control;
return false;
}
if (position > c_form[control_index].list_length) {
form_error = form_error_invalid_list_index;
return false;
}
if (!c_form[control_index].active) {
form_error = form_error_invalid_control;
return false;
}
c_form[control_index].list[position].id = new_id;
return true;
}
bool set_default_controls(int primary, int cancel) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((primary < -1) || (primary > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if ((cancel < -1) || (cancel > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (primary > -1 && (c_form[primary].type != ct_button || !c_form[primary].active)) {
form_error = form_error_invalid_control;
return false;
}
if (cancel > -1 && (c_form[cancel].type != ct_button || !c_form[cancel].active)) {
form_error = form_error_invalid_control;
return false;
}
if (primary > -1)
set_primary(primary, true, true);
else {
int defaults = get_default_button();
if (defaults > -1)
set_primary(defaults, false, true);
}
if (cancel > -1)
set_cancel(cancel, true, true);
else {
int cancels = get_cancel_button();
if (cancels > -1)
set_cancel(cancels, false, true);
}
return true;
}
bool set_button_attributes(int control_index, bool primary, bool cancel, bool overwrite = true) {
form_error = 0;
if (!active) {
form_error = form_error_no_window;
return false;
}
if ((control_index < 0) || (control_index > c_form.length() - 1)) {
form_error = form_error_invalid_index;
return false;
}
if (c_form[control_index].type != ct_button) {
form_error = form_error_invalid_control;
return false;
}