forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpgEntry.I
More file actions
684 lines (633 loc) · 26.6 KB
/
pgEntry.I
File metadata and controls
684 lines (633 loc) · 26.6 KB
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
// Filename: pgEntry.I
// Created by: drose (13Mar02)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: PGEntry::set_text
// Access: Published
// Description: Changes the text currently displayed within the
// entry. This uses the Unicode encoding currently
// specified for the "focus" TextNode; therefore, the
// TextNode must exist before calling set_text().
//
// The return value is true if all the text is accepted,
// or false if some was truncated (see set_max_width(),
// etc.).
////////////////////////////////////////////////////////////////////
INLINE bool PGEntry::
set_text(const string &text) {
LightReMutexHolder holder(_lock);
TextNode *text_node = get_text_def(S_focus);
nassertr(text_node != (TextNode *)NULL, false);
return set_wtext(text_node->decode_text(text));
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_plain_text
// Access: Published
// Description: Returns the text currently displayed within the
// entry, without any embedded properties characters.
//
// This uses the Unicode encoding currently specified
// for the "focus" TextNode; therefore, the TextNode
// must exist before calling get_text().
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_plain_text() const {
LightReMutexHolder holder(_lock);
TextNode *text_node = get_text_def(S_focus);
nassertr(text_node != (TextNode *)NULL, string());
return text_node->encode_wtext(get_plain_wtext());
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_text
// Access: Published
// Description: Returns the text currently displayed within the
// entry. This uses the Unicode encoding currently
// specified for the "focus" TextNode; therefore, the
// TextNode must exist before calling get_text().
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_text() const {
LightReMutexHolder holder(_lock);
TextNode *text_node = get_text_def(S_focus);
nassertr(text_node != (TextNode *)NULL, string());
return text_node->encode_wtext(get_wtext());
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_num_characters
// Access: Published
// Description: Returns the number of characters of text in the
// entry. This is the actual number of visible
// characters, not counting implicit newlines due to
// wordwrapping, or formatted characters for text
// properties changes. If there is an embedded
// TextGraphic object, it counts as one character.
//
// This is also the length of the string returned by
// get_plain_text().
////////////////////////////////////////////////////////////////////
INLINE int PGEntry::
get_num_characters() const {
LightReMutexHolder holder(_lock);
return _text.get_num_characters();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_character
// Access: Published
// Description: Returns the character at the indicated position in
// the entry. If the object at this position is a
// graphic object instead of a character, returns 0.
////////////////////////////////////////////////////////////////////
INLINE wchar_t PGEntry::
get_character(int n) const {
LightReMutexHolder holder(_lock);
return _text.get_character(n);
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_graphic
// Access: Published
// Description: Returns the graphic object at the indicated position
// in the pre-wordwrapped string. If the object at this
// position is a character instead of a graphic object,
// returns NULL.
////////////////////////////////////////////////////////////////////
INLINE const TextGraphic *PGEntry::
get_graphic(int n) const {
LightReMutexHolder holder(_lock);
return _text.get_graphic(n);
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_properties
// Access: Published
// Description: Returns the TextProperties in effect for the object
// at the indicated position in the pre-wordwrapped
// string.
////////////////////////////////////////////////////////////////////
INLINE const TextProperties &PGEntry::
get_properties(int n) const {
LightReMutexHolder holder(_lock);
return _text.get_properties(n);
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::set_cursor_position
// Access: Published
// Description: Sets the current position of the cursor. This is the
// position within the text at which the next letter
// typed by the user will be inserted; normally it is
// the same as the length of the text.
////////////////////////////////////////////////////////////////////
INLINE void PGEntry::
set_cursor_position(int position) {
LightReMutexHolder holder(_lock);
if (_cursor_position != position) {
_cursor_position = position;
_cursor_stale = true;
_blink_start = ClockObject::get_global_clock()->get_frame_time();
}
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_cursor_position
// Access: Published
// Description: Returns the current position of the cursor.
////////////////////////////////////////////////////////////////////
INLINE int PGEntry::
get_cursor_position() const {
LightReMutexHolder holder(_lock);
return _cursor_position;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_cursor_X
// Access: Published
// Description: Returns the node position x of the cursor
////////////////////////////////////////////////////////////////////
INLINE PN_stdfloat PGEntry::
get_cursor_X() const {
LightReMutexHolder holder(_lock);
return _cursor_def.get_x();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_cursor_y
// Access: Published
// Description: Returns the node position y of the cursor
////////////////////////////////////////////////////////////////////
INLINE PN_stdfloat PGEntry::
get_cursor_Y() const {
LightReMutexHolder holder(_lock);
return _cursor_def.get_y();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::set_max_chars
// Access: Published
// Description: Sets the maximum number of characters that may be
// typed into the entry. This is a limit on the number
// of characters, as opposed to the width of the entry;
// see also set_max_width().
//
// If this is 0, there is no limit.
////////////////////////////////////////////////////////////////////
INLINE void PGEntry::
set_max_chars(int max_chars) {
LightReMutexHolder holder(_lock);
_max_chars = max_chars;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_max_chars
// Access: Published
// Description: Returns the current maximum number of characters that
// may be typed into the entry, or 0 if there is no
// limit. See set_max_chars().
////////////////////////////////////////////////////////////////////
INLINE int PGEntry::
get_max_chars() const {
LightReMutexHolder holder(_lock);
return _max_chars;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::set_max_width
// Access: Published
// Description: Sets the maximum width of all characters that may be
// typed into the entry. This is a limit on the width
// of the formatted text, not a fixed limit on the
// number of characters; also set_max_chars().
//
// If this is 0, there is no limit.
//
// If _num_lines is more than 1, rather than being a
// fixed width on the whole entry, this becomes instead
// the wordwrap width (and the width limit on the entry
// is essentially _max_width * _num_lines).
////////////////////////////////////////////////////////////////////
INLINE void PGEntry::
set_max_width(PN_stdfloat max_width) {
LightReMutexHolder holder(_lock);
_max_width = max_width;
_text_geom_stale = true;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_max_width
// Access: Published
// Description: Returns the current maximum width of the characters
// that may be typed into the entry, or 0 if there is no
// limit. See set_max_width().
////////////////////////////////////////////////////////////////////
INLINE PN_stdfloat PGEntry::
get_max_width() const {
LightReMutexHolder holder(_lock);
return _max_width;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::set_num_lines
// Access: Published
// Description: Sets the number of lines of text the PGEntry will
// use. This only has meaning if _max_width is not 0;
// _max_width indicates the wordwrap width of each line.
////////////////////////////////////////////////////////////////////
INLINE void PGEntry::
set_num_lines(int num_lines) {
LightReMutexHolder holder(_lock);
nassertv(num_lines >= 1);
_num_lines = num_lines;
_text_geom_stale = true;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_num_lines
// Access: Published
// Description: Returns the number of lines of text the PGEntry will
// use, if _max_width is not 0. See set_num_lines().
////////////////////////////////////////////////////////////////////
INLINE int PGEntry::
get_num_lines() const {
LightReMutexHolder holder(_lock);
return _num_lines;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::set_blink_rate
// Access: Published
// Description: Sets the number of times per second the cursor will
// blink while the entry has keyboard focus.
//
// If this is 0, the cursor does not blink, but is held
// steady.
////////////////////////////////////////////////////////////////////
INLINE void PGEntry::
set_blink_rate(PN_stdfloat blink_rate) {
LightReMutexHolder holder(_lock);
_blink_rate = blink_rate;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_blink_rate
// Access: Published
// Description: Returns the number of times per second the cursor
// will blink, or 0 if the cursor is not to blink.
////////////////////////////////////////////////////////////////////
INLINE PN_stdfloat PGEntry::
get_blink_rate() const {
LightReMutexHolder holder(_lock);
return _blink_rate;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_cursor_def
// Access: Published
// Description: Returns the Node that will be rendered to represent
// the cursor. You can attach suitable cursor geometry
// to this node.
////////////////////////////////////////////////////////////////////
INLINE NodePath PGEntry::
get_cursor_def() {
LightReMutexHolder holder(_lock);
return _cursor_def;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::clear_cursor_def
// Access: Published
// Description: Removes all the children from the cursor_def node, in
// preparation for adding a new definition.
////////////////////////////////////////////////////////////////////
INLINE void PGEntry::
clear_cursor_def() {
LightReMutexHolder holder(_lock);
_cursor_def.remove_node();
_cursor_def = _cursor_scale.attach_new_node("cursor");
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::set_cursor_keys_active
// Access: Published
// Description: Sets whether the arrow keys (and home/end) control
// movement of the cursor. If true, they are active; if
// false, they are ignored.
////////////////////////////////////////////////////////////////////
INLINE void PGEntry::
set_cursor_keys_active(bool flag) {
LightReMutexHolder holder(_lock);
_cursor_keys_active = flag;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_cursor_keys_active
// Access: Published
// Description: Returns whether the arrow keys are currently set to
// control movement of the cursor; see
// set_cursor_keys_active().
////////////////////////////////////////////////////////////////////
INLINE bool PGEntry::
get_cursor_keys_active() const {
LightReMutexHolder holder(_lock);
return _cursor_keys_active;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::set_obscure_mode
// Access: Published
// Description: Specifies whether obscure mode should be enabled. In
// obscure mode, a string of asterisks is displayed
// instead of the literal text, e.g. for entering
// passwords.
//
// In obscure mode, the width of the text is computed
// based on the width of the string of asterisks, not on
// the width of the actual text. This has implications
// on the maximum length of text that may be entered if
// max_width is in effect.
////////////////////////////////////////////////////////////////////
INLINE void PGEntry::
set_obscure_mode(bool flag) {
LightReMutexHolder holder(_lock);
if (_obscure_mode != flag) {
_obscure_mode = flag;
_text_geom_stale = true;
}
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_obscure_mode
// Access: Published
// Description: Specifies whether obscure mode is enabled. See
// set_obscure_mode().
////////////////////////////////////////////////////////////////////
INLINE bool PGEntry::
get_obscure_mode() const {
LightReMutexHolder holder(_lock);
return _obscure_mode;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::set_overflow_mode
// Access: Published
// Description: Specifies whether overflow mode should be enabled.
// In overflow mode, text can overflow the boundaries
// of the Entry element horizontally.
//
// Overflow mode only works when the number of lines
// is 1.
////////////////////////////////////////////////////////////////////
INLINE void PGEntry::
set_overflow_mode(bool flag) {
LightReMutexHolder holder(_lock);
if (_overflow_mode != flag) {
_overflow_mode = flag;
_text_geom_stale = true;
_cursor_stale = true;
}
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_overflow_mode
// Access: Published
// Description: Specifies whether overflow mode is enabled. See
// set_overflow_mode().
////////////////////////////////////////////////////////////////////
INLINE bool PGEntry::
get_overflow_mode() const {
LightReMutexHolder holder(_lock);
return _overflow_mode;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::set_candidate_active
// Access: Published
// Description: Specifies the name of the TextProperties structure
// added to the TextPropertiesManager that will be used
// to render candidate strings from the IME, used for
// typing characters in east Asian languages. Each
// candidate string represents one possible way to
// interpret the sequence of keys the user has just
// entered; it should not be considered typed yet, but
// it is important for the user to be able to see what
// he is considering entering.
//
// This particular method sets the properties for the
// subset of the current candidate string that the user
// can actively scroll through.
////////////////////////////////////////////////////////////////////
INLINE void PGEntry::
set_candidate_active(const string &candidate_active) {
LightReMutexHolder holder(_lock);
_candidate_active = candidate_active;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_candidate_active
// Access: Published
// Description: See set_candidate_active().
////////////////////////////////////////////////////////////////////
INLINE const string &PGEntry::
get_candidate_active() const {
LightReMutexHolder holder(_lock);
return _candidate_active;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::set_candidate_inactive
// Access: Published
// Description: Specifies the name of the TextProperties structure
// added to the TextPropertiesManager that will be used
// to render candidate strings from the IME, used for
// typing characters in east Asian languages. Each
// candidate string represents one possible way to
// interpret the sequence of keys the user has just
// entered; it should not be considered typed yet, but
// it is important for the user to be able to see what
// he is considering entering.
//
// This particular method sets the properties for the
// subset of the current candidate string that the user
// is not actively scrolling through.
////////////////////////////////////////////////////////////////////
INLINE void PGEntry::
set_candidate_inactive(const string &candidate_inactive) {
LightReMutexHolder holder(_lock);
_candidate_inactive = candidate_inactive;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_candidate_inactive
// Access: Published
// Description: See set_candidate_inactive().
////////////////////////////////////////////////////////////////////
INLINE const string &PGEntry::
get_candidate_inactive() const {
LightReMutexHolder holder(_lock);
return _candidate_inactive;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_accept_prefix
// Access: Published, Static
// Description: Returns the prefix that is used to define the accept
// event for all PGEntries. The accept event is the
// concatenation of this string followed by get_id().
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_accept_prefix() {
return "accept-";
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_accept_failed_prefix
// Access: Published, Static
// Description: Returns the prefix that is used to define the accept
// failed event for all PGEntries. This event is the
// concatenation of this string followed by get_id().
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_accept_failed_prefix() {
return "acceptfailed-";
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_overflow_prefix
// Access: Published, Static
// Description: Returns the prefix that is used to define the overflow
// event for all PGEntries. The overflow event is the
// concatenation of this string followed by get_id().
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_overflow_prefix() {
return "overflow-";
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_type_prefix
// Access: Published, Static
// Description: Returns the prefix that is used to define the type
// event for all PGEntries. The type event is the
// concatenation of this string followed by get_id().
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_type_prefix() {
return "type-";
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_erase_prefix
// Access: Published, Static
// Description: Returns the prefix that is used to define the erase
// event for all PGEntries. The erase event is the
// concatenation of this string followed by get_id().
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_erase_prefix() {
return "erase-";
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_cursormove_prefix
// Access: Published, Static
// Description: Returns the prefix that is used to define the cursor
// event for all PGEntries. The cursor event is the
// concatenation of this string followed by get_id().
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_cursormove_prefix() {
return "cursormove-";
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_accept_event
// Access: Published
// Description: Returns the event name that will be thrown when the
// entry is accepted normally.
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_accept_event(const ButtonHandle &button) const {
return get_accept_prefix() + button.get_name() + "-" + get_id();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_accept_failed_event
// Access: Published
// Description: Returns the event name that will be thrown when the
// entry cannot accept an input
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_accept_failed_event(const ButtonHandle &button) const {
return get_accept_failed_prefix() + button.get_name() + "-" + get_id();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_overflow_event
// Access: Published
// Description: Returns the event name that will be thrown when too
// much text is attempted to be entered into the
// PGEntry, exceeding either the limit set via
// set_max_chars() or via set_max_width().
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_overflow_event() const {
return get_overflow_prefix() + get_id();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_type_event
// Access: Published
// Description: Returns the event name that will be thrown whenever
// the user extends the text by typing.
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_type_event() const {
return get_type_prefix() + get_id();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_erase_event
// Access: Published
// Description: Returns the event name that will be thrown whenever
// the user erases characters in the text.
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_erase_event() const {
return get_erase_prefix() + get_id();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_cursormove_event
// Access: Published
// Description: Returns the event name that will be thrown whenever
// the cursor moves
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_cursormove_event() const {
return get_cursormove_prefix() + get_id();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::set_wtext
// Access: Published
// Description: Changes the text currently displayed within the
// entry.
//
// The return value is true if all the text is accepted,
// or false if some was truncated (see set_max_width(),
// etc.).
////////////////////////////////////////////////////////////////////
INLINE bool PGEntry::
set_wtext(const wstring &wtext) {
LightReMutexHolder holder(_lock);
bool ret = _text.set_wtext(wtext);
if (_obscure_mode) {
ret = _obscure_text.set_wtext(wstring(_text.get_num_characters(), '*'));
}
_text_geom_stale = true;
set_cursor_position(min(_cursor_position, _text.get_num_characters()));
return ret;
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_plain_wtext
// Access: Published
// Description: Returns the text currently displayed within the
// entry, without any embedded properties characters.
////////////////////////////////////////////////////////////////////
INLINE wstring PGEntry::
get_plain_wtext() const {
LightReMutexHolder holder(_lock);
return _text.get_plain_wtext();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_wtext
// Access: Published
// Description: Returns the text currently displayed within the
// entry.
////////////////////////////////////////////////////////////////////
INLINE wstring PGEntry::
get_wtext() const {
LightReMutexHolder holder(_lock);
return _text.get_wtext();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::set_accept_enabled
// Access: Published
// Description: Sets whether the input may be accepted--use to
// disable submission by the user
////////////////////////////////////////////////////////////////////
INLINE void PGEntry::
set_accept_enabled(bool enabled) {
LightReMutexHolder holder(_lock);
_accept_enabled = enabled;
}