Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGNumberEntry.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Daniel Sigg 03/09/2001
3
4/*************************************************************************
5 * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12
13/** \class TGNumberEntry
14 \ingroup guiwidgets
15
16TGNumberEntry is a number entry input widget with up/down buttons.
17TGNumberEntryField is a number entry input widget.
18TGNumberFormat contains enum types to specify the numeric format.
19
20The number entry widget is based on TGTextEntry but allows only
21numerical input. The widget support numerous formats including
22integers, hex numbers, real numbers, fixed fraction reals and
23time/date formats. The widget also allows to restrict input values
24to non-negative or positive numbers and to specify explicit limits.
25
26The following styles are supported:
27 - kNESInteger: integer number
28 - kNESRealOne: real number with one digit (no exponent)
29 - kNESRealTwo: real number with two digits (no exponent)
30 - kNESRealThree: real number with three digits (no exponent)
31 - kNESRealFour: real number with four digits (no exponent)
32 - kNESReal: arbitrary real number
33 - kNESDegree: angle in degree:minutes:seconds format
34 - kNESMinSec: time in minutes:seconds format
35 - kNESHourMin: time in hour:minutes format
36 - kNESHourMinSec: time in hour:minutes:seconds format
37 - kNESDayMYear: date in day/month/year format
38 - kNESMDayYear: date in month/day/year format
39 - kNESHex: hex number
40
41The following attributes can be specified:
42 - kNEAAnyNumber: any number is allowed
43 - kNEANonNegative: only non-negative numbers are allowed
44 - kNEAPositive: only positive numbers are allowed
45
46Explicit limits can be specified individually:
47 - kNELNoLimits: no limits
48 - kNELLimitMin: lower limit only
49 - kNELLimitMax upper limit only
50 - kNELLimitMinMax both lower and upper limits
51
52TGNumberEntryField is a plain vanilla entry field, whereas
53TGNumberEntry adds two small buttons to increase and decrease the
54numerical value in the field. The number entry widgets also support
55using the up and down cursor keys to change the numerical values.
56The step size can be selected with control and shift keys:
57 - -- small step (1 unit/factor of 3)
58 - shift medium step (10 units/factor of 10)
59 - control large step (100 units/factor of 30)
60 - shift-control huge step (1000 units/factor of 100)
61
62The steps are either linear or logarithmic. The default behaviour
63is set when the entry field is created, but it can be changed by
64pressing the alt key at the same time.
65
66Changing the number in the widget will generate the event:
67 - kC_TEXTENTRY, kTE_TEXTCHANGED, widget id, 0.
68Hitting the enter key will generate:
69 - kC_TEXTENTRY, kTE_ENTER, widget id, 0.
70Hitting the tab key will generate:
71 - kC_TEXTENTRY, kTE_TAB, widget id, 0.
72
73*/
74
75
76#include "TGNumberEntry.h"
77#include "KeySymbols.h"
78#include "TTimer.h"
79#include "TSystem.h"
80#include "TGToolTip.h"
81#include "TMath.h"
82#include "TVirtualX.h"
83#include "strlcpy.h"
84#include "snprintf.h"
85
86#include <cctype>
87#include <iostream>
88
89
94
95
96
97//////////////////////////////////////////////////////////////////////////
98// //
99// Miscellaneous routines for handling numeric values <-> strings //
100// //
101//////////////////////////////////////////////////////////////////////////
102
103//______________________________________________________________________________
104enum ERealStyle { // Style of real
105 kRSInt = 0, // Integer
106 kRSFrac = 1, // Fraction only
107 kRSExpo = 2, // Exponent only
108 kRSFracExpo = 3 // Fraction and Exponent
110
111////////////////////////////////////////////////////////////////////////////////
112
114 ERealStyle fStyle{kRSInt}; // Style of real
115 Int_t fFracDigits{0}; // Number of fractional digits
116 Int_t fFracBase{0}; // Base of fractional digits
117 Int_t fIntNum{0}; // Integer number
118 Int_t fFracNum{0}; // Fraction
119 Int_t fExpoNum{0}; // Exponent
120 Int_t fSign{0}; // Sign
121};
122
123////////////////////////////////////////////////////////////////////////////////
124
125const Double_t kEpsilon = 1E-12;
126
127////////////////////////////////////////////////////////////////////////////////
128
129const Int_t kDays[13] =
130 { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
131
132////////////////////////////////////////////////////////////////////////////////
133
135{
136 if (x > 0) {
137 return (Long_t) (x + 0.5);
138 } else if (x < 0) {
139 return (Long_t) (x - 0.5);
140 } else {
141 return 0;
142 }
143}
144
145////////////////////////////////////////////////////////////////////////////////
146
148{
149 if (x > 0) {
150 return (Long_t) (x + kEpsilon);
151 } else if (x < 0) {
152 return (Long_t) (x - kEpsilon);
153 } else {
154 return 0;
155 }
156}
157
158////////////////////////////////////////////////////////////////////////////////
159
161{
162 return ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)));
163}
164
165////////////////////////////////////////////////////////////////////////////////
166
169{
170 if (isdigit(c)) {
171 return kTRUE;
172 }
173 if (isxdigit(c) && (style == TGNumberFormat::kNESHex)) {
174 return kTRUE;
175 }
176 if ((c == '-') && (style == TGNumberFormat::kNESInteger) &&
178 return kTRUE;
179 }
180 if ((c == '-') &&
189 return kTRUE;
190 }
191 if ((c == '-') && (style == TGNumberFormat::kNESReal)) {
192 return kTRUE;
193 }
194 if (((c == '.') || (c == ',')) &&
206 return kTRUE;
207 }
208 if ((c == ':') &&
215 return kTRUE;
216 }
217 if ((c == '/') &&
220 return kTRUE;
221 }
222 if (((c == 'e') || (c == 'E')) && (style == TGNumberFormat::kNESReal)) {
223 return kTRUE;
224 }
225 return kFALSE;
226}
227
228////////////////////////////////////////////////////////////////////////////////
229
230static char *EliminateGarbage(char *text,
233{
234 if (text == 0) {
235 return 0;
236 }
237 for (Int_t i = strlen(text) - 1; i >= 0; i--) {
238 if (!IsGoodChar(text[i], style, attr)) {
239 memmove(text + i, text + i + 1, strlen(text) - i);
240 }
241 }
242 return text;
243}
244
245////////////////////////////////////////////////////////////////////////////////
246
247static Long_t IntStr(const char *text)
248{
249 Long_t l = 0;
250 Int_t sign = 1;
251 for (UInt_t i = 0; i < strlen(text); i++) {
252 if (text[i] == '-') {
253 sign = -1;
254 } else if ((isdigit(text[i])) && (l < kMaxLong)) {
255 l = 10 * l + (text[i] - '0');
256 }
257 }
258 return sign * l;
259}
260
261////////////////////////////////////////////////////////////////////////////////
262
263static char *StrInt(char *text, Long_t i, Int_t digits)
264{
265 snprintf(text, 250, "%li", TMath::Abs(i));
266 TString s = text;
267 while (digits > s.Length()) {
268 s = "0" + s;
269 }
270 if (i < 0) {
271 s = "-" + s;
272 }
273 strlcpy(text, (const char *) s, 250);
274 return text;
275}
276
277////////////////////////////////////////////////////////////////////////////////
278
279static TString StringInt(Long_t i, Int_t digits)
280{
281 char text[256];
282 StrInt(text, i, digits);
283 return TString(text);
284}
285
286////////////////////////////////////////////////////////////////////////////////
287
288static char *RealToStr(char *text, const RealInfo_t & ri)
289{
290 char *p = text;
291 if (text == 0) {
292 return 0;
293 }
294 strlcpy(p, "", 256);
295 if (ri.fSign < 0) {
296 strlcpy(p, "-", 256);
297 p++;
298 }
299 StrInt(p, TMath::Abs(ri.fIntNum), 0);
300 p += strlen(p);
301 if ((ri.fStyle == kRSFrac) || (ri.fStyle == kRSFracExpo)) {
302 strlcpy(p, ".", 256-strlen(p));
303 p++;
305 p += strlen(p);
306 }
307 if ((ri.fStyle == kRSExpo) || (ri.fStyle == kRSFracExpo)) {
308 strlcpy(p, "e", 256-strlen(p));
309 p++;
310 StrInt(p, ri.fExpoNum, 0);
311 p += strlen(p);
312 }
313 return text;
314}
315
316////////////////////////////////////////////////////////////////////////////////
317
318static Double_t StrToReal(const char *text, RealInfo_t & ri)
319{
320 char *s;
321 char *frac;
322 char *expo;
323 char *minus;
324 char buf[256];
325
326 if ((text == 0) || (!text[0])) {
327 ri.fStyle = kRSInt;
328 ri.fIntNum = 0;
329 ri.fSign = 1;
330 return 0.0;
331 }
332 strlcpy(buf, text, sizeof(buf));
333 s = buf;
334 frac = strchr(s, '.');
335 if (frac == 0) {
336 frac = strchr(s, ',');
337 }
338 expo = strchr(s, 'e');
339 minus = strchr(s, '-');
340 if (expo == 0) {
341 expo = strchr(s, 'E');
342 }
343 if ((frac != 0) && (expo != 0) && (frac > expo)) {
344 frac = 0;
345 }
346 if ((minus != 0) && ((expo == 0) || (minus < expo))) {
347 ri.fSign = -1;
348 } else {
349 ri.fSign = 1;
350 }
351 if ((frac == 0) && (expo == 0)) {
352 ri.fStyle = kRSInt;
353 } else if (frac == 0) {
354 ri.fStyle = kRSExpo;
355 } else if (expo == 0) {
356 ri.fStyle = kRSFrac;
357 } else {
358 ri.fStyle = kRSFracExpo;
359 }
360 if (frac != 0) {
361 *frac = 0;
362 frac++;
363 }
364 if (expo != 0) {
365 *expo = 0;
366 expo++;
367 }
368 ri.fIntNum = TMath::Abs(IntStr(s));
369 if (expo != 0) {
370 ri.fExpoNum = IntStr(expo);
371 } else {
372 ri.fExpoNum = 0;
373 }
374 if (ri.fExpoNum > 999) {
375 ri.fExpoNum = 999;
376 }
377 if (ri.fExpoNum < -999) {
378 ri.fExpoNum = -999;
379 }
380 ri.fFracDigits = 0;
381 ri.fFracBase = 1;
382 ri.fFracNum = 0;
383 if (frac != 0) {
384 for (UInt_t i = 0; i < strlen(frac); i++) {
385 if (isdigit(frac[i])) {
386 if (ri.fFracNum + 9 < kMaxInt / 10) {
387 ri.fFracNum = 10 * ri.fFracNum + (frac[i] - '0');
388 ri.fFracDigits++;
389 ri.fFracBase *= 10;
390 }
391 }
392 }
393 }
394 if ((ri.fFracDigits == 0) && (ri.fStyle == kRSFrac)) {
395 ri.fStyle = kRSInt;
396 }
397 if ((ri.fFracDigits == 0) && (ri.fStyle == kRSFracExpo)) {
398 ri.fStyle = kRSExpo;
399 }
400 switch (ri.fStyle) {
401 case kRSInt:
402 return ri.fSign * ri.fIntNum;
403 case kRSFrac:
404 return ri.fSign *
405 (ri.fIntNum + (Double_t) ri.fFracNum / ri.fFracBase);
406 case kRSExpo:
407 return ri.fSign * (ri.fIntNum * TMath::Power(10, ri.fExpoNum));
408 case kRSFracExpo:
409 return ri.fSign * (ri.fIntNum +
410 (Double_t) ri.fFracNum / ri.fFracBase) *
411 TMath::Power(10, ri.fExpoNum);
412 }
413 return 0;
414}
415
416////////////////////////////////////////////////////////////////////////////////
417
418static ULong_t HexStrToInt(const char *s)
419{
420 ULong_t w = 0;
421 for (UInt_t i = 0; i < strlen(s); i++) {
422 if ((s[i] >= '0') && (s[i] <= '9')) {
423 w = 16 * w + (s[i] - '0');
424 } else if ((toupper(s[i]) >= 'A') && (toupper(s[i]) <= 'F')) {
425 w = 16 * w + (toupper(s[i]) - 'A' + 10);
426 }
427 }
428 return w;
429}
430
431////////////////////////////////////////////////////////////////////////////////
432
433static char *IntToHexStr(char *text, ULong_t l)
434{
435 const char *const digits = "0123456789ABCDEF";
436 char buf[64];
437 char *p = buf + 62;
438 // coverity[secure_coding]
439 strcpy(p, "");
440 while (l > 0) {
441 *(--p) = digits[l % 16];
442 l /= 16;
443 }
444 if (!p[0]) {
445 // coverity[secure_coding]
446 strcpy(text, "0");
447 } else {
448 // coverity[secure_coding]
449 strcpy(text, p);
450 }
451 return text;
452}
453
454////////////////////////////////////////////////////////////////////////////////
455
456static char *MIntToStr(char *text, Long_t l, Int_t digits)
457{
458 TString s;
459 Int_t base;
460 switch (digits) {
461 case 0:
462 base = 1;
463 break;
464 case 1:
465 base = 10;
466 break;
467 case 2:
468 base = 100;
469 break;
470 case 3:
471 base = 1000;
472 break;
473 default:
474 case 4:
475 base = 10000;
476 break;
477 }
478 s = StringInt(TMath::Abs(l) / base, 0) + "." +
479 StringInt(TMath::Abs(l) % base, digits);
480 if (l < 0) {
481 s = "-" + s;
482 }
483 strlcpy(text, (const char *) s, 256);
484 return text;
485}
486
487////////////////////////////////////////////////////////////////////////////////
488
489static char *DIntToStr(char *text, Long_t l, Bool_t Sec, char Del)
490{
491 TString s;
492 if (Sec) {
493 s = StringInt(TMath::Abs(l) / 3600, 0) + Del +
494 StringInt((TMath::Abs(l) % 3600) / 60, 2) + Del +
495 StringInt(TMath::Abs(l) % 60, 2);
496 } else {
497 s = StringInt(TMath::Abs(l) / 60, 0) + Del +
498 StringInt(TMath::Abs(l) % 60, 2);
499 }
500 if (l < 0) {
501 s = "-" + s;
502 }
503 strlcpy(text, (const char *) s, 256);
504 return text;
505}
506
507////////////////////////////////////////////////////////////////////////////////
508
509static void GetNumbers(const char *s, Int_t & Sign,
510 Long_t & n1, Int_t maxd1,
511 Long_t & n2, Int_t maxd2,
512 Long_t & n3, Int_t maxd3, const char *Delimiters)
513{
514 Long_t n;
515 Long_t d = 0;
516 Sign = +1;
517 n1 = 0;
518 n2 = 0;
519 n3 = 0;
520 if (*s == '-') {
521 Sign = -1;
522 s++;
523 }
524 if (!isdigit(*s) && !strchr(Delimiters, *s)) {
525 return;
526 }
527 while ((*s != 0) && ((strchr(Delimiters, *s) == 0) || (maxd2 == 0))) {
528 if (isdigit(*s) && (d < maxd1)) {
529 if (n1 < kMaxLong) {
530 n1 = 10 * n1 + (*s - '0');
531 }
532 d++;
533 }
534 s++;
535 }
536 if (strcspn(s, Delimiters) == strlen(s)) {
537 return;
538 }
539 Int_t dummy = 0;
540 GetNumbers(s + 1, dummy, n2, maxd2, n3, maxd3, n, d, Delimiters);
541}
542
543////////////////////////////////////////////////////////////////////////////////
544
546{
547 while (TMath::Abs(l) >= Max) {
548 l /= 10;
549 }
550 return l;
551}
552
553////////////////////////////////////////////////////////////////////////////////
554
555static void AppendFracZero(char *text, Int_t digits)
556{
557 char *p;
558 Int_t found = 0;
559 p = strchr(text, '.');
560 if (p == 0) {
561 p = strchr(text, ',');
562 }
563 if (p == 0) {
564 return;
565 }
566 p++;
567 for (UInt_t i = 0; i < strlen(p); i++) {
568 if (isdigit(*p)) {
569 found++;
570 }
571 }
572 while (found < digits) {
573 // coverity[secure_coding]
574 strcpy(p + strlen(p), "0");
575 found++;
576 }
577}
578
579////////////////////////////////////////////////////////////////////////////////
580/// Create a number entry with year/month/day information.
581
582static Long_t MakeDateNumber(const char * /*text*/, Long_t Day,
583 Long_t Month, Long_t Year)
584{
585 Day = TMath::Abs(Day);
586 Month = TMath::Abs(Month);
587 Year = TMath::Abs(Year);
588 if (Year < 100) {
589 Year += 2000;
590 }
591 Month = GetSignificant(Month, 100);
592 if (Month > 12)
593 Month = 12;
594 if (Month == 0)
595 Month = 1;
596 Day = GetSignificant(Day, 100);
597 if (Day == 0)
598 Day = 1;
599 if (Day > kDays[Month])
600 Day = kDays[Month];
601 if ((Month == 2) && (Day > 28) && !IsLeapYear(Year))
602 Day = 28;
603 return 10000 * Year + 100 * Month + Day;
604}
605
606////////////////////////////////////////////////////////////////////////////////
607/// Translate a string to a number value.
608
609static Long_t TranslateToNum(const char *text,
611{
612 Long_t n1;
613 Long_t n2;
614 Long_t n3;
615 Int_t sign;
616 switch (style) {
618 GetNumbers(text, sign, n1, 12, n2, 0, n3, 0, "");
619 return sign * n1;
621 GetNumbers(text, sign, n1, 12, n2, 1, n3, 0, ".,");
622 return sign * (10 * n1 + GetSignificant(n2, 10));
624 {
625 char buf[256];
626 strlcpy(buf, text, sizeof(buf));
627 AppendFracZero(buf, 2);
628 GetNumbers(buf, sign, n1, 12, n2, 2, n3, 0, ".,");
629 return sign * (100 * n1 + GetSignificant(n2, 100));
630 }
632 {
633 char buf[256];
634 strlcpy(buf, text, sizeof(buf));
635 AppendFracZero(buf, 3);
636 GetNumbers(buf, sign, n1, 12, n2, 3, n3, 0, ".,");
637 return sign * (1000 * n1 + GetSignificant(n2, 1000));
638 }
640 {
641 char buf[256];
642 strlcpy(buf, text, sizeof(buf));
643 AppendFracZero(buf, 4);
644 GetNumbers(buf, sign, n1, 12, n2, 4, n3, 0, ".,");
645 return sign * (10000 * n1 + GetSignificant(n2, 10000));
646 }
648 return (Long_t) StrToReal(text, ri);
650 GetNumbers(text, sign, n1, 12, n2, 2, n3, 2, ".,:");
651 return sign * (3600 * n1 + 60 * GetSignificant(n2, 60) +
652 GetSignificant(n3, 60));
654 GetNumbers(text, sign, n1, 12, n2, 2, n3, 2, ".,:");
655 return 3600 * n1 + 60 * GetSignificant(n2, 60) +
656 GetSignificant(n3, 60);
658 GetNumbers(text, sign, n1, 12, n2, 2, n3, 0, ".,:");
659 return sign * (60 * n1 + GetSignificant(n2, 60));
661 GetNumbers(text, sign, n1, 12, n2, 2, n3, 0, ".,:");
662 return 60 * n1 + GetSignificant(n2, 60);
664 GetNumbers(text, sign, n1, 2, n2, 2, n3, 4, ".,/");
665 return MakeDateNumber(text, n1, n2, n3);
667 GetNumbers(text, sign, n2, 2, n1, 2, n3, 4, ".,/");
668 return MakeDateNumber(text, n1, n2, n3);
670 return HexStrToInt(text);
671 }
672 return 0;
673}
674
675////////////////////////////////////////////////////////////////////////////////
676/// Translate a number value to a string.
677
678static char *TranslateToStr(char *text, Long_t l,
680{
681 switch (style) {
683 return StrInt(text, l, 0);
685 return MIntToStr(text, l, 1);
687 return MIntToStr(text, l, 2);
689 return MIntToStr(text, l, 3);
691 return MIntToStr(text, l, 4);
693 return RealToStr(text, ri);
695 return DIntToStr(text, l, kTRUE, '.');
697 return DIntToStr(text, l % (24 * 3600), kTRUE, ':');
699 return DIntToStr(text, l, kFALSE, ':');
701 return DIntToStr(text, l % (24 * 60), kFALSE, ':');
703 {
704 TString date =
705 StringInt(TMath::Abs(l) % 100, 0) + "/" +
706 StringInt((TMath::Abs(l) / 100) % 100, 0) + "/" +
707 StringInt(TMath::Abs(l) / 10000, 0);
708 strlcpy(text, (const char *) date, 256);
709 return text;
710 }
712 {
713 TString date =
714 StringInt((TMath::Abs(l) / 100) % 100, 0) + "/" +
715 StringInt(TMath::Abs(l) % 100, 0) + "/" +
716 StringInt(TMath::Abs(l) / 10000, 0);
717 strlcpy(text, (const char *) date, 256);
718 return text;
719 }
721 return IntToHexStr(text, (ULong_t) l);
722 }
723 return 0;
724}
725
726////////////////////////////////////////////////////////////////////////////////
727/// Convert to double format.
728
730{
731 switch (ri.fStyle) {
732 // Integer type real
733 case kRSInt:
734 return (Double_t) ri.fSign * ri.fIntNum;
735 // Fraction type real
736 case kRSFrac:
737 return (Double_t) ri.fSign * ((Double_t) TMath::Abs(ri.fIntNum) +
738 (Double_t) ri.fFracNum / ri.fFracBase);
739 // Exponent only
740 case kRSExpo:
741 return (Double_t) ri.fSign * ri.fIntNum *
742 TMath::Power(10, ri.fExpoNum);
743 // Fraction and exponent
744 case kRSFracExpo:
745 return (Double_t) ri.fSign * ((Double_t) TMath::Abs(ri.fIntNum) +
746 (Double_t) ri.fFracNum /
747 ri.fFracBase) * TMath::Power(10,
748 ri.fExpoNum);
749 }
750 return 0;
751}
752
753////////////////////////////////////////////////////////////////////////////////
754/// Check min/max limits for the set value.
755
758 Double_t min, Double_t max)
759{
760 if ((limits == TGNumberFormat::kNELNoLimits) ||
762 return;
763 }
764 // check min
765 if ((limits == TGNumberFormat::kNELLimitMin) ||
767 Long_t lower;
768 switch (style) {
770 lower = Round(10.0 * min);
771 break;
773 lower = Round(100.0 * min);
774 break;
776 lower = Round(1000.0 * min);
777 break;
779 lower = Round(10000.0 * min);
780 break;
782 lower = (ULong_t) Round(min);
783 break;
784 default:
785 lower = Round(min);
786 break;
787 }
789 if (l < lower)
790 l = lower;
791 } else {
792 if (lower < 0)
793 lower = 0;
794 if ((ULong_t) l < (ULong_t) lower)
795 l = lower;
796 }
797 }
798 // check max
799 if ((limits == TGNumberFormat::kNELLimitMax) ||
801 Long_t upper;
802 switch (style) {
804 upper = Round(10.0 * max);
805 break;
807 upper = Round(100.0 * max);
808 break;
810 upper = Round(1000.0 * max);
811 break;
813 upper = Round(10000.0 * max);
814 break;
816 upper = (ULong_t) Round(max);
817 break;
818 default:
819 upper = Round(max);
820 break;
821 }
823 if (l > upper)
824 l = upper;
825 } else {
826 if (upper < 0)
827 upper = 0;
828 if ((ULong_t) l > (ULong_t) upper)
829 l = upper;
830 }
831 }
832}
833
834////////////////////////////////////////////////////////////////////////////////
835/// Convert to double format.
836
837static void IncreaseReal(RealInfo_t & ri, Double_t mag, Bool_t logstep,
840 Double_t max = 1)
841{
842 Double_t x = RealToDouble(ri);
843
844 // apply step
845 if (logstep) {
846 x *= mag;
847 } else {
848 switch (ri.fStyle) {
849 case kRSInt:
850 x = x + mag;
851 break;
852 case kRSFrac:
853 x = x + mag / ri.fFracBase;
854 break;
855 case kRSExpo:
856 x = x + mag * TMath::Power(10, ri.fExpoNum);
857 break;
858 case kRSFracExpo:
859 x = x + (mag / ri.fFracBase) * TMath::Power(10, ri.fExpoNum);
860 break;
861 }
862 }
863 // check min
864 if ((limits == TGNumberFormat::kNELLimitMin) ||
866 if (x < min)
867 x = min;
868 }
869 // check max
870 if ((limits == TGNumberFormat::kNELLimitMax) ||
872 if (x > max)
873 x = max;
874 }
875 // check format after log step
876 if ((x != 0) && logstep && (TMath::Abs(mag) > kEpsilon)) {
877 for (int j = 0; j < 10; j++) {
878 // Integer: special case
879 if ((ri.fStyle == kRSInt) && (TMath::Abs(x) < 1) &&
880 (TMath::Abs(x) > kEpsilon)) {
881 ri.fStyle = kRSFrac;
882 ri.fFracDigits = 1;
883 ri.fFracBase = 10;
884 continue;
885 }
886 if ((ri.fStyle == kRSInt) && (TMath::Abs(x) > 10000)) {
887 ri.fStyle = kRSFracExpo;
888 ri.fExpoNum = 4;
889 ri.fFracDigits = 4;
890 ri.fFracBase = 10000;
891 Long_t rest = Round(TMath::Abs(x)) % 10000;
892 for (int k = 0; k < 4; k++) {
893 if (rest % 10 != 0) {
894 break;
895 }
896 ri.fFracDigits--;
897 ri.fFracBase /= 10;
898 rest /= 10;
899 }
900 if (ri.fFracDigits == 0) {
901 ri.fStyle = kRSExpo;
902 }
903 continue;
904 }
905 if (ri.fStyle == kRSInt)
906 break;
907
908 // calculate first digit
909 Double_t y;
910 if ((ri.fStyle == kRSExpo) || (ri.fStyle == kRSFracExpo)) {
911 y = TMath::Abs(x) * TMath::Power(10, -ri.fExpoNum);
912 } else {
913 y = TMath::Abs(x);
914 }
915 // adjust exponent if num < 1
916 if ((Truncate(y) == 0) && (y > 0.001)) {
917 if ((ri.fStyle == kRSExpo) || (ri.fStyle == kRSFracExpo)) {
918 ri.fExpoNum--;
919 } else {
920 ri.fStyle = kRSFracExpo;
921 ri.fExpoNum = -1;
922 }
923 continue;
924 }
925 // adjust exponent if num > 10
926 if (Truncate(y) >= 10) {
927 if ((ri.fStyle == kRSExpo) || (ri.fStyle == kRSFracExpo)) {
928 ri.fExpoNum++;
929 } else {
930 ri.fStyle = kRSFracExpo;
931 ri.fExpoNum = 1;
932 }
933 continue;
934 }
935 break;
936 }
937 }
938 // convert back to RealInfo_t
939 switch (ri.fStyle) {
940 // Integer type real
941 case kRSInt:
942 {
943 ri.fSign = (x < 0) ? -1 : 1;
944 ri.fIntNum = Round(TMath::Abs(x));
945 break;
946 }
947 // Fraction type real
948 case kRSFrac:
949 {
950 ri.fSign = (x < 0) ? -1 : 1;
953 break;
954 }
955 // Exponent only
956 case kRSExpo:
957 {
958 ri.fSign = (x < 0) ? -1 : 1;
959 ri.fIntNum = Round(TMath::Abs(x) * TMath::Power(10, -ri.fExpoNum));
960 if (ri.fIntNum == 0) {
961 ri.fStyle = kRSInt;
962 }
963 break;
964 }
965 // Fraction and exponent
966 case kRSFracExpo:
967 {
968 ri.fSign = (x < 0) ? -1 : 1;
970 ri.fIntNum = Truncate(y);
971 ri.fFracNum = Round((y - TMath::Abs(ri.fIntNum)) * ri.fFracBase);
972 if ((ri.fIntNum == 0) && (ri.fFracNum == 0)) {
973 ri.fStyle = kRSFrac;
974 }
975 break;
976 }
977 }
978
979 // check if the back conversion violated limits
980 if (limits != TGNumberFormat::kNELNoLimits) {
981 x = RealToDouble(ri);
982 // check min
983 if ((limits == TGNumberFormat::kNELLimitMin) ||
985 if (x < min) {
986 char text[256];
987 snprintf(text, 255, "%g", min);
988 StrToReal(text, ri);
989 }
990 }
991 // check max
992 if ((limits == TGNumberFormat::kNELLimitMax) ||
994 if (x > max) {
995 char text[256];
996 snprintf(text, 255, "%g", max);
997 StrToReal(text, ri);
998 }
999 }
1000 }
1001}
1002
1003////////////////////////////////////////////////////////////////////////////////
1004/// Change year/month/day format.
1005
1007{
1008 Long_t year;
1009 Long_t month;
1010 Long_t day;
1011
1012 // get year/month/day format
1013 year = l / 10000;
1014 month = (TMath::Abs(l) / 100) % 100;
1015 if (month > 12)
1016 month = 12;
1017 if (month == 0)
1018 month = 1;
1019 day = TMath::Abs(l) % 100;
1020 if (day > kDays[month])
1021 day = kDays[month];
1022 if ((month == 2) && (day > 28) && !IsLeapYear(year)) {
1023 day = 28;
1024 }
1025 if (day == 0)
1026 day = 0;
1027
1028 // apply step
1029 if (step == TGNumberFormat::kNSSHuge) {
1030 year += sign * 10;
1031 } else if (step == TGNumberFormat::kNSSLarge) {
1032 year += sign;
1033 } else if (step == TGNumberFormat::kNSSMedium) {
1034 month += sign;
1035 if (month > 12) {
1036 month = 1;
1037 year++;
1038 }
1039 if (month < 1) {
1040 month = 12;
1041 year--;
1042 }
1043 } else if (step == TGNumberFormat::kNSSSmall) {
1044 day += sign;
1045 if ((sign > 0) &&
1046 ((day > kDays[month]) ||
1047 ((month == 2) && (day > 28) && !IsLeapYear(year)))) {
1048 day = 1;
1049 month++;
1050 if (month > 12) {
1051 month = 1;
1052 year++;
1053 }
1054 }
1055 if ((sign < 0) && (day == 0)) {
1056 month--;
1057 if (month < 1) {
1058 month = 12;
1059 year--;
1060 }
1061 day = kDays[month];
1062 }
1063 }
1064 // check again for valid date
1065 if (year < 0)
1066 year = 0;
1067 if (day > kDays[month])
1068 day = kDays[month];
1069 if ((month == 2) && (day > 28) && !IsLeapYear(year)) {
1070 day = 28;
1071 }
1072 l = 10000 * year + 100 * month + day;
1073}
1074
1075
1076
1077
1078////////////////////////////////////////////////////////////////////////////////
1079/// Constructs a number entry field.
1080
1082 Double_t val, GContext_t norm,
1084 Pixel_t back)
1085 : TGTextEntry(p, new TGTextBuffer(), id, norm, font, option, back),
1086 fNeedsVerification(kFALSE), fNumStyle(kNESReal), fNumAttr(kNEAAnyNumber),
1087 fNumLimits(kNELNoLimits), fNumMin(0.0), fNumMax(1.0)
1088{
1089 fStepLog = kFALSE;
1091 SetNumber(val);
1093}
1094
1095////////////////////////////////////////////////////////////////////////////////
1096/// Constructs a number entry field.
1097
1099 Int_t id, Double_t val,
1101 ELimit limits, Double_t min,
1102 Double_t max)
1103 : TGTextEntry(parent, "", id), fNeedsVerification(kFALSE), fNumStyle(style),
1104 fNumAttr(attr), fNumLimits(limits), fNumMin(min), fNumMax(max)
1105{
1106 fStepLog = kFALSE;
1108 SetNumber(val);
1110}
1111
1112////////////////////////////////////////////////////////////////////////////////
1113/// Set the numeric value (floating point representation).
1114
1116{
1117 switch (fNumStyle) {
1118 case kNESInteger:
1119 SetIntNumber(Round(val), emit);
1120 break;
1121 case kNESRealOne:
1122 SetIntNumber(Round(10.0 * val), emit);
1123 break;
1124 case kNESRealTwo:
1125 SetIntNumber(Round(100.0 * val), emit);
1126 break;
1127 case kNESRealThree:
1128 SetIntNumber(Round(1000.0 * val), emit);
1129 break;
1130 case kNESRealFour:
1131 SetIntNumber(Round(10000.0 * val), emit);
1132 break;
1133 case kNESReal:
1134 {
1135 char text[256];
1136 snprintf(text, 255, "%g", val);
1137 SetText(text, emit);
1138 break;
1139 }
1140 case kNESDegree:
1141 SetIntNumber(Round(val), emit);
1142 break;
1143 case kNESHourMinSec:
1144 SetIntNumber(Round(val), emit);
1145 break;
1146 case kNESMinSec:
1147 SetIntNumber(Round(val), emit);
1148 break;
1149 case kNESHourMin:
1150 SetIntNumber(Round(val), emit);
1151 break;
1152 case kNESDayMYear:
1153 SetIntNumber(Round(val), emit);
1154 break;
1155 case kNESMDayYear:
1156 SetIntNumber(Round(val), emit);
1157 break;
1158 case kNESHex:
1159 SetIntNumber((UInt_t) (TMath::Abs(val) + 0.5), emit);
1160 break;
1161 }
1162}
1163
1164////////////////////////////////////////////////////////////////////////////////
1165/// Set the numeric value (integer representation).
1166
1168{
1169 char text[256];
1170 RealInfo_t ri;
1171 if (fNumStyle == kNESReal) {
1172 TranslateToStr(text, val, kNESInteger, ri);
1173 } else {
1174 TranslateToStr(text, val, fNumStyle, ri);
1175 }
1176 SetText(text, emit);
1177}
1178
1179////////////////////////////////////////////////////////////////////////////////
1180/// Set the numeric value (time format).
1181
1183{
1184 switch (fNumStyle) {
1185 case kNESHourMinSec:
1186 SetIntNumber(3600 * TMath::Abs(hour) + 60 * TMath::Abs(min) +
1187 TMath::Abs(sec), emit);
1188 break;
1189 case kNESMinSec:
1190 {
1191 SetIntNumber(60 * min + sec, emit);
1192 break;
1193 }
1194 case kNESHourMin:
1195 SetIntNumber(60 * TMath::Abs(hour) + TMath::Abs(min), emit);
1196 break;
1197 default:
1198 break;
1199 }
1200}
1201
1202////////////////////////////////////////////////////////////////////////////////
1203/// Set the numeric value (date format).
1204
1206{
1207 switch (fNumStyle) {
1208 case kNESDayMYear:
1209 case kNESMDayYear:
1210 {
1211 SetIntNumber(10000 * TMath::Abs(year) + 100 * TMath::Abs(month) +
1212 TMath::Abs(day), emit);
1213 }
1214 default:
1215 {
1216 break;
1217 }
1218 }
1219}
1220
1221////////////////////////////////////////////////////////////////////////////////
1222/// Set the numeric value (hex format).
1223
1225{
1226 SetIntNumber((Long_t) val, emit);
1227}
1228
1229////////////////////////////////////////////////////////////////////////////////
1230/// Set the value (text format).
1231
1233{
1234 char buf[256];
1235 strlcpy(buf, text, sizeof(buf));
1237 TGTextEntry::SetText(buf, emit);
1239}
1240
1241////////////////////////////////////////////////////////////////////////////////
1242/// Get the numeric value (floating point representation).
1243
1245{
1246 switch (fNumStyle) {
1247 case kNESInteger:
1248 return (Double_t) GetIntNumber();
1249 case kNESRealOne:
1250 return (Double_t) GetIntNumber() / 10.0;
1251 case kNESRealTwo:
1252 return (Double_t) GetIntNumber() / 100.0;
1253 case kNESRealThree:
1254 return (Double_t) GetIntNumber() / 1000.0;
1255 case kNESRealFour:
1256 return (Double_t) GetIntNumber() / 10000.0;
1257 case kNESReal:
1258 {
1259 char text[256];
1260 RealInfo_t ri;
1261 strlcpy(text, GetText(), sizeof(text));
1262 return StrToReal(text, ri);
1263 }
1264 case kNESDegree:
1265 return (Double_t) GetIntNumber();
1266 case kNESHourMinSec:
1267 return (Double_t) GetIntNumber();
1268 case kNESMinSec:
1269 return (Double_t) GetIntNumber();
1270 case kNESHourMin:
1271 return (Double_t) GetIntNumber();
1272 case kNESDayMYear:
1273 return (Double_t) GetIntNumber();
1274 case kNESMDayYear:
1275 return (Double_t) GetIntNumber();
1276 case kNESHex:
1277 return (Double_t) (ULong_t) GetIntNumber();
1278 }
1279 return 0;
1280}
1281
1282////////////////////////////////////////////////////////////////////////////////
1283/// Get the numeric value (integer representation).
1284
1286{
1287 RealInfo_t ri;
1288 return TranslateToNum(GetText(), fNumStyle, ri);
1289}
1290
1291////////////////////////////////////////////////////////////////////////////////
1292/// Get the numeric value (time format).
1293
1294void TGNumberEntryField::GetTime(Int_t & hour, Int_t & min, Int_t & sec) const
1295{
1296 switch (fNumStyle) {
1297 case kNESHourMinSec:
1298 {
1299 Long_t l = GetIntNumber();
1300 hour = TMath::Abs(l) / 3600;
1301 min = (TMath::Abs(l) % 3600) / 60;
1302 sec = TMath::Abs(l) % 60;
1303 break;
1304 }
1305 case kNESMinSec:
1306 {
1307 Long_t l = GetIntNumber();
1308 hour = 0;
1309 min = TMath::Abs(l) / 60;
1310 sec = TMath::Abs(l) % 60;
1311 if (l < 0) {
1312 min *= -1;
1313 sec *= -1;
1314 }
1315 break;
1316 }
1317 case kNESHourMin:
1318 {
1319 Long_t l = GetIntNumber();
1320 hour = TMath::Abs(l) / 60;
1321 min = TMath::Abs(l) % 60;
1322 sec = 0;
1323 break;
1324 }
1325 default:
1326 {
1327 hour = 0;
1328 min = 0;
1329 sec = 0;
1330 break;
1331 }
1332 }
1333}
1334
1335////////////////////////////////////////////////////////////////////////////////
1336/// Get the numeric value (date format).
1337
1338void TGNumberEntryField::GetDate(Int_t & year, Int_t & month, Int_t & day) const
1339{
1340 switch (fNumStyle) {
1341 case kNESDayMYear:
1342 case kNESMDayYear:
1343 {
1344 Long_t l = GetIntNumber();
1345 year = l / 10000;
1346 month = (l % 10000) / 100;
1347 day = l % 100;
1348 break;
1349 }
1350 default:
1351 {
1352 year = 0;
1353 month = 0;
1354 day = 0;
1355 break;
1356 }
1357 }
1358}
1359
1360////////////////////////////////////////////////////////////////////////////////
1361/// Get the numeric value (hex format).
1362
1364{
1365 return (ULong_t) GetIntNumber();
1366}
1367
1368////////////////////////////////////////////////////////////////////////////////
1369/// Get the text width in pixels.
1370
1372{
1373 return gVirtualX->TextWidth(fFontStruct, text, strlen(text));
1374}
1375
1376////////////////////////////////////////////////////////////////////////////////
1377/// Increase the number value.
1378
1380 Int_t stepsign, Bool_t logstep)
1381{
1382 Long_t l = 0;
1383 RealInfo_t ri;
1384 Long_t mag = 0;
1385 Double_t rmag = 0.0;
1386 Int_t sign = stepsign;
1387
1388 // save old text field
1389 TString oldtext = GetText();
1390 // Get number
1391 if (fNumStyle != kNESReal) {
1392 l = GetIntNumber();
1393 } else {
1394 StrToReal(oldtext, ri);
1395 }
1396
1397 // magnitude of step
1398 if ((fNumStyle == kNESDegree) || (fNumStyle == kNESHourMinSec) ||
1401 (fNumStyle == kNESHex)) {
1402 logstep = kFALSE;
1403 switch (step) {
1404 case kNSSSmall:
1405 mag = 1;
1406 break;
1407 case kNSSMedium:
1408 mag = 10;
1409 break;
1410 case kNSSLarge:
1411 mag = 100;
1412 break;
1413 case kNSSHuge:
1414 mag = 1000;
1415 break;
1416 }
1417 } else {
1418 Int_t msd = TMath::Abs((fNumStyle == kNESReal) ? ri.fIntNum : l);
1419 while (msd >= 10)
1420 msd /= 10;
1421 Bool_t odd = (msd < 3);
1422 if (sign < 0)
1423 odd = !odd;
1424 switch (step) {
1425 case kNSSSmall:
1426 rmag = (!logstep) ? 1. : (odd ? 3. : 10. / 3.);
1427 break;
1428 case kNSSMedium:
1429 rmag = 10.;
1430 break;
1431 case kNSSLarge:
1432 rmag = (!logstep) ? 100. : (odd ? 30. : 100. / 3.);
1433 break;
1434 case kNSSHuge:
1435 rmag = (!logstep) ? 1000. : 100.;
1436 break;
1437 }
1438 if (sign < 0)
1439 rmag = logstep ? 1. / rmag : -rmag;
1440 }
1441
1442 // sign of step
1443 if (sign == 0) {
1444 logstep = kFALSE;
1445 rmag = 0;
1446 mag = 0;
1447 } else {
1448 sign = (sign > 0) ? 1 : -1;
1449 }
1450 // add/multiply step
1451 switch (fNumStyle) {
1452 case kNESInteger:
1453 case kNESRealOne:
1454 case kNESRealTwo:
1455 case kNESRealThree:
1456 case kNESRealFour:
1457 {
1458 l = logstep ? Round(l * rmag) : Round(l + rmag);
1460 if ((l < 0) && (fNumAttr == kNEANonNegative))
1461 l = 0;
1462 if ((l <= 0) && (fNumAttr == kNEAPositive))
1463 l = 1;
1464 break;
1465 }
1466 case kNESReal:
1467 {
1468 IncreaseReal(ri, rmag, logstep, fNumLimits, fNumMin, fNumMax);
1469 if (((fNumAttr == kNEANonNegative) ||
1470 (fNumAttr == kNEAPositive)) && (ri.fSign < 0)) {
1471 ri.fIntNum = 0;
1472 ri.fFracNum = 0;
1473 ri.fExpoNum = 0;
1474 ri.fSign = 1;
1475 }
1476 break;
1477 }
1478 case kNESDegree:
1479 {
1480 if (mag > 60)
1481 l += sign * 36 * mag;
1482 else if (mag > 6)
1483 l += sign * 6 * mag;
1484 else
1485 l += sign * mag;
1487 if ((l < 0) && (fNumAttr == kNEANonNegative))
1488 l = 0;
1489 if ((l <= 0) && (fNumAttr == kNEAPositive))
1490 l = 1;
1491 break;
1492 }
1493 case kNESHourMinSec:
1494 {
1495 if (mag > 60)
1496 l += sign * 36 * mag;
1497 else if (mag > 6)
1498 l += sign * 6 * mag;
1499 else
1500 l += sign * mag;
1502 if (l < 0)
1503 l = (24 * 3600) - ((-l) % (24 * 3600));
1504 if (l > 0)
1505 l = l % (24 * 3600);
1506 break;
1507 }
1508 case kNESMinSec:
1509 {
1510 if (mag > 6)
1511 l += sign * 6 * mag;
1512 else
1513 l += sign * mag;
1515 if ((l < 0) && (fNumAttr == kNEANonNegative))
1516 l = 0;
1517 if ((l <= 0) && (fNumAttr == kNEAPositive))
1518 l = 1;
1519 break;
1520 }
1521 case kNESHourMin:
1522 {
1523 if (mag > 6)
1524 l += sign * 6 * mag;
1525 else
1526 l += sign * mag;
1528 if (l < 0)
1529 l = (24 * 60) - ((-l) % (24 * 60));
1530 if (l > 0)
1531 l = l % (24 * 60);
1532 break;
1533 }
1534 case kNESDayMYear:
1535 case kNESMDayYear:
1536 {
1537 IncreaseDate(l, step, sign);
1539 break;
1540 }
1541 case kNESHex:
1542 {
1543 ULong_t ll = (ULong_t) l;
1544 if (mag > 500)
1545 ll += sign * 4096 * mag / 1000;
1546 else if (mag > 50)
1547 ll += sign * 256 * mag / 100;
1548 else if (mag > 5)
1549 ll += sign * 16 * mag / 10;
1550 else
1551 ll += sign * mag;
1552 l = (Long_t) ll;
1554 break;
1555 }
1556 }
1557 if (fNumStyle != kNESReal) {
1558 SetIntNumber(l);
1559 } else {
1560 char buf[256];
1561 RealToStr(buf, ri);
1562 SetText(buf);
1563 }
1564}
1565
1566////////////////////////////////////////////////////////////////////////////////
1567/// Set the numerical format.
1568
1570{
1571 Double_t val = GetNumber();
1572 fNumStyle = style;
1573 fNumAttr = attr;
1574 if ((fNumAttr != kNEAAnyNumber) && (val < 0))
1575 val = 0;
1576 SetNumber(val);
1577 // make sure we have a valid number by increasing it by 0
1579}
1580
1581////////////////////////////////////////////////////////////////////////////////
1582/// Set the numerical limits.
1583
1585 Double_t min, Double_t max)
1586{
1587 Double_t val = GetNumber();
1588 fNumLimits = limits;
1589 fNumMin = min;
1590 fNumMax = max;
1591 SetNumber(val);
1592 // make sure we have a valid number by increasing it by 0
1594}
1595
1596////////////////////////////////////////////////////////////////////////////////
1597/// Set the active state.
1598
1600{
1601 if (!state && fNeedsVerification) {
1602 // make sure we have a valid number by increasing it by 0
1604 }
1605 TGTextEntry::SetState(state);
1606}
1607
1608////////////////////////////////////////////////////////////////////////////////
1609/// Handle keys.
1610
1612{
1613 if (!IsEnabled()) {
1615 }
1616
1617 Int_t n;
1618 char tmp[10];
1619 UInt_t keysym;
1620 gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
1621 n = strlen(tmp);
1622
1623 // intercept up key
1624 if ((EKeySym) keysym == kKey_Up) {
1625 // Get log step / alt key
1626 Bool_t logstep = fStepLog;
1627 if (event->fState & kKeyMod1Mask)
1628 logstep = !logstep;
1629 // shift-cntrl-up
1630 if ((event->fState & kKeyShiftMask) &&
1631 (event->fState & kKeyControlMask)) {
1632 IncreaseNumber(kNSSHuge, 1, logstep);
1633 }
1634 // cntrl-up
1635 else if (event->fState & kKeyControlMask) {
1636 IncreaseNumber(kNSSLarge, 1, logstep);
1637
1638 }
1639 // shift-up
1640 else if (event->fState & kKeyShiftMask) {
1641 IncreaseNumber(kNSSMedium, 1, logstep);
1642 }
1643
1644 // up
1645 else {
1646 IncreaseNumber(kNSSSmall, 1, logstep);
1647 }
1648 return kTRUE;
1649 }
1650 // intercept down key
1651 else if ((EKeySym) keysym == kKey_Down) {
1652 // Get log step / alt key
1653 Bool_t logstep = fStepLog;
1654 if (event->fState & kKeyMod1Mask)
1655 logstep = !logstep;
1656 // shift-cntrl-down
1657 if ((event->fState & kKeyShiftMask) &&
1658 (event->fState & kKeyControlMask)) {
1659 IncreaseNumber(kNSSHuge, -1, logstep);
1660 }
1661 // cntrl-down
1662 else if (event->fState & kKeyControlMask) {
1663 IncreaseNumber(kNSSLarge, -1, logstep);
1664 }
1665 // shift-down
1666 else if (event->fState & kKeyShiftMask) {
1667 IncreaseNumber(kNSSMedium, -1, logstep);
1668 }
1669 // down
1670 else {
1671 IncreaseNumber(kNSSSmall, -1, logstep);
1672 }
1673 return kTRUE;
1674 }
1675 // intercept printable characters
1676 else if (n && (keysym < 127) && (keysym >= 32) &&
1677 ((EKeySym) keysym != kKey_Delete) &&
1678 ((EKeySym) keysym != kKey_Backspace) &&
1679 ((event->fState & kKeyControlMask) == 0)) {
1680 if (IsGoodChar(tmp[0], fNumStyle, fNumAttr)) {
1682 } else {
1683 return kTRUE;
1684 }
1685 }
1686 // otherwise use default behaviour
1687 else {
1689 }
1690}
1691
1692////////////////////////////////////////////////////////////////////////////////
1693/// Handle focus change.
1694
1696{
1697 if (IsEnabled() && fNeedsVerification &&
1698 (event->fCode == kNotifyNormal) &&
1699 (event->fState != kNotifyPointer) && (event->fType == kFocusOut)) {
1700 // make sure we have a valid number by increasing it by 0
1702 }
1703
1705}
1706
1707////////////////////////////////////////////////////////////////////////////////
1708/// Text has changed message.
1709
1711{
1714}
1715
1716////////////////////////////////////////////////////////////////////////////////
1717/// Return was pressed.
1718
1720{
1721 TString instr, outstr;
1722 instr = TGTextEntry::GetBuffer()->GetString();
1723
1724 if (fNeedsVerification) {
1725 // make sure we have a valid number by increasing it by 0
1727 }
1728 outstr = TGTextEntry::GetBuffer()->GetString();
1729 if (instr != outstr) {
1730 InvalidInput(instr);
1731 gVirtualX->Bell(0);
1732 }
1734}
1735
1736////////////////////////////////////////////////////////////////////////////////
1737/// Layout.
1738
1740{
1741 if (GetAlignment() == kTextRight) {
1742 End(kFALSE);
1743 } else {
1744 Home(kFALSE);
1745 }
1746}
1747
1748//////////////////////////////////////////////////////////////////////////
1749// //
1750// TGNumberEntryLayout //
1751// //
1752// Layout manager for number entry widget //
1753// //
1754//////////////////////////////////////////////////////////////////////////
1755
1756
1757////////////////////////////////////////////////////////////////////////////////
1758/// Layout the internal GUI elements in use.
1759
1761{
1762 if (fBox == 0) {
1763 return;
1764 }
1765 UInt_t w = fBox->GetWidth();
1766 UInt_t h = fBox->GetHeight();
1767 UInt_t upw = 2 * h / 3;
1768 UInt_t uph = h / 2;
1769 Int_t upx = (w > h) ? (Int_t) w - (Int_t) upw : -1000;
1770 Int_t upy = 0;
1771 Int_t downx = (w > h) ? (Int_t) w - (Int_t) upw : -1000;
1772 Int_t downy = h / 2;
1773 UInt_t downw = upw;
1774 UInt_t downh = h - downy;
1775 UInt_t numw = (w > h) ? w - upw : w;
1776 UInt_t numh = h;
1777 if (fBox->GetNumberEntry())
1778 fBox->GetNumberEntry()->MoveResize(0, 0, numw, numh);
1779 if (fBox->GetButtonUp())
1780 fBox->GetButtonUp()->MoveResize(upx, upy, upw, uph);
1781 if (fBox->GetButtonDown())
1782 fBox->GetButtonDown()->MoveResize(downx, downy, downw, downh);
1783}
1784
1785////////////////////////////////////////////////////////////////////////////////
1786/// Return the default size of the numeric control box.
1787
1789{
1790 return fBox->GetSize();
1791}
1792
1793
1794
1795//////////////////////////////////////////////////////////////////////////
1796// //
1797// TRepeatTimer //
1798// //
1799// Timer for numeric control box buttons. //
1800// //
1801//////////////////////////////////////////////////////////////////////////
1802
1803class TGRepeatFireButton;
1804
1805////////////////////////////////////////////////////////////////////////////////
1806
1807class TRepeatTimer : public TTimer {
1808private:
1810
1811public:
1813 : TTimer(ms, kTRUE), fButton(button) { }
1814 Bool_t Notify() override;
1815};
1816
1817
1818
1819//////////////////////////////////////////////////////////////////////////
1820// //
1821// TRepeatFireButton //
1822// //
1823// Picture button which fires repeatedly as long as the button is pressed //
1824// //
1825//////////////////////////////////////////////////////////////////////////
1826
1827////////////////////////////////////////////////////////////////////////////////
1828
1830protected:
1831 TRepeatTimer *fTimer; // the timer
1832 Int_t fIgnoreNextFire; // flag for skipping next
1833 TGNumberFormat::EStepSize fStep; // increment/decrement step
1834 Bool_t fStepLog; // logarithmic step flag
1835 Bool_t fDoLogStep; // flag for using logarithmic step
1836
1838
1839public:
1841 Int_t id, Bool_t logstep)
1842 : TGPictureButton(p, pic, id), fTimer(0), fIgnoreNextFire(0),
1843 fStep(TGNumberFormat::kNSSSmall), fStepLog(logstep), fDoLogStep(logstep)
1845 virtual ~TGRepeatFireButton() { delete fTimer; }
1846
1847 Bool_t HandleButton(Event_t *event) override;
1848 void FireButton();
1849 virtual void SetLogStep(Bool_t on = kTRUE) { fStepLog = on; }
1850};
1851
1852////////////////////////////////////////////////////////////////////////////////
1853/// Return kTRUE if one of the parents is in edit mode.
1854
1856{
1857 TGWindow *parent = (TGWindow*)GetParent();
1858
1859 while (parent && (parent != fClient->GetDefaultRoot())) {
1860 if (parent->IsEditable()) {
1861 return kTRUE;
1862 }
1863 parent = (TGWindow*)parent->GetParent();
1864 }
1865 return kFALSE;
1866}
1867
1868////////////////////////////////////////////////////////////////////////////////
1869/// Handle messages for number entry widget according to the user input.
1870
1872{
1873 const Int_t t0 = 200;
1874 if (fTip)
1875 fTip->Hide();
1876
1877 // disable button handling while gui building
1878 if (IsEditableParent()) {
1879 return kTRUE;
1880 }
1881
1882 if (fState == kButtonDisabled)
1883 return kTRUE;
1884
1885 if (event->fType == kButtonPress) {
1886 // Get log step / alt key
1888 if (event->fState & kKeyMod1Mask)
1890 if ((event->fState & kKeyShiftMask) &&
1891 (event->fState & kKeyControlMask)) {
1893 } else if (event->fState & kKeyControlMask) {
1895 } else if (event->fState & kKeyShiftMask) {
1897 } else {
1899 }
1901 fIgnoreNextFire = 0;
1902 FireButton();
1903 fIgnoreNextFire = 2;
1904
1905 if (fTimer == 0) {
1906 fTimer = new TRepeatTimer(this, t0);
1907 }
1908 fTimer->Reset();
1910 } else {
1912 if (fTimer != 0) {
1913 fTimer->Remove();
1914 fTimer->SetTime(t0);
1915 }
1916 }
1917
1918 return kTRUE;
1919}
1920
1921////////////////////////////////////////////////////////////////////////////////
1922/// Process messages for fire button.
1923
1925{
1926 if (fIgnoreNextFire <= 0) {
1928 fWidgetId, (Long_t) fStep + (fDoLogStep ? 100 : 0));
1929 } else {
1931 }
1932}
1933
1934////////////////////////////////////////////////////////////////////////////////
1935/// Notify when timer times out and reset the timer.
1936
1938{
1940 Reset();
1941 if ((Long64_t)fTime > 20) fTime -= 10;
1942 return kFALSE;
1943}
1944
1945////////////////////////////////////////////////////////////////////////////////
1946/// Constructs a numeric entry widget.
1947
1949 Double_t val, Int_t wdigits, Int_t id,
1950 EStyle style,
1952 ELimit limits, Double_t min, Double_t max)
1953 : TGCompositeFrame(parent, 10 * wdigits, 25), fButtonToNum(kTRUE)
1954{
1955 fWidgetId = id;
1956 fMsgWindow = parent;
1957 fPicUp = fClient->GetPicture("arrow_up.xpm");
1958 if (!fPicUp)
1959 Error("TGNumberEntry", "arrow_up.xpm not found");
1960 fPicDown = fClient->GetPicture("arrow_down.xpm");
1961 if (!fPicDown)
1962 Error("TGNumberEntry", "arrow_down.xpm not found");
1963
1964 // create gui elements
1965 fNumericEntry = new TGNumberEntryField(this, id, val, style, attr,
1966 limits, min, max);
1967 fNumericEntry->Connect("ReturnPressed()", "TGNumberEntry", this,
1968 "ValueSet(Long_t=0)");
1969 fNumericEntry->Connect("ReturnPressed()", "TGNumberEntry", this,
1970 "Modified()");
1973 fButtonUp = new TGRepeatFireButton(this, fPicUp, 1,
1975 fButtonUp->Associate(this);
1976 AddFrame(fButtonUp, 0);
1979 fButtonDown->Associate(this);
1981
1982 // resize
1984 Int_t charw = fNumericEntry->GetCharWidth("0123456789");
1985 Int_t w = charw * TMath::Abs(wdigits) / 10 + 8 + 2 * h / 3;
1987 MapSubwindows();
1988 Resize(w, h);
1990}
1991
1992////////////////////////////////////////////////////////////////////////////////
1993/// Destructs a numeric entry widget.
1994
1996{
1997 gClient->FreePicture(fPicUp);
1998 gClient->FreePicture(fPicDown);
1999
2000 Cleanup();
2001}
2002
2003////////////////////////////////////////////////////////////////////////////////
2004/// Make w the window that will receive the generated messages.
2005
2007{
2010}
2011
2012////////////////////////////////////////////////////////////////////////////////
2013/// Set log steps.
2014
2016{
2020}
2021
2022////////////////////////////////////////////////////////////////////////////////
2023/// Set the active state.
2024
2026{
2027 if (enable) {
2031 } else {
2035 }
2036}
2037
2038////////////////////////////////////////////////////////////////////////////////
2039/// Send button messages to the number field (true) or parent widget (false).
2040/// When the message is sent to the parent widget, it is responsible to change
2041/// the numerical value accordingly. This can be useful to implement cursors
2042/// which move from data point to data point. For the message being sent
2043/// see ProcessMessage().
2044
2046{
2047 fButtonToNum = state;
2048}
2049
2050////////////////////////////////////////////////////////////////////////////////
2051/// Process the up/down button messages. If fButtonToNum is false the
2052/// following message is sent: kC_COMMAND, kCM_BUTTON, widget id, param
2053/// param % 100 is the step size
2054/// param % 10000 / 100 != 0 indicates log step
2055/// param / 10000 != 0 indicates button down
2056
2058{
2059 switch (GET_MSG(msg)) {
2060 case kC_COMMAND:
2061 {
2062 if ((GET_SUBMSG(msg) == kCM_BUTTON) &&
2063 (parm1 >= 1) && (parm1 <= 2)) {
2064 if (fButtonToNum) {
2065 Int_t sign = (parm1 == 1) ? 1 : -1;
2066 EStepSize step = (EStepSize) (parm2 % 100);
2067 Bool_t logstep = (parm2 >= 100);
2068 fNumericEntry->IncreaseNumber(step, sign, logstep);
2069 } else {
2071 10000 * (parm1 - 1) + parm2);
2072 ValueChanged(10000 * (parm1 - 1) + parm2);
2073 }
2074 // Emit a signal needed by pad editor
2075 ValueSet(10000 * (parm1 - 1) + parm2);
2076 Modified();
2077 }
2078 break;
2079 }
2080 }
2081 return kTRUE;
2082}
2083
2084
2085////////////////////////////////////////////////////////////////////////////////
2086/// Return layout manager.
2087
2089{
2090 TGNumberEntry *entry = (TGNumberEntry*)this;
2091
2092 if (entry->fLayoutManager->IsA() != TGNumberEntryLayout::Class()) {
2093 entry->SetLayoutManager(new TGNumberEntryLayout(entry));
2094 }
2095
2096 return entry->fLayoutManager;
2097}
2098
2099////////////////////////////////////////////////////////////////////////////////
2100/// Emit ValueChanged(Long_t) signal. This signal is emitted when
2101/// fButtonToNum is false. The val has the following meaning:
2102/// val % 100 is the step size
2103/// val % 10000 / 100 != 0 indicates log step
2104/// val / 10000 != 0 indicates button down
2105
2107{
2108 Emit("ValueChanged(Long_t)", val);
2109}
2110
2111////////////////////////////////////////////////////////////////////////////////
2112/// Emit ValueSet(Long_t) signal. This signal is emitted when the
2113/// number entry value is changed. The val has the following meaning:
2114/// val % 100 is the step size
2115/// val % 10000 / 100 != 0 indicates log step
2116/// val / 10000 != 0 indicates button down
2117
2119{
2120 Emit("ValueSet(Long_t)", val);
2121}
2122
2123////////////////////////////////////////////////////////////////////////////////
2124/// Emit Modified() signal. This signal is emitted when the
2125/// number entry value is changed.
2126
2128{
2129 Emit("Modified()");
2130}
2131
2132////////////////////////////////////////////////////////////////////////////////
2133/// Save a number entry widget as a C++ statement(s) on output stream out.
2134
2135void TGNumberEntry::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2136{
2137 char quote = '"';
2138
2139 // to calculate the digits parameter
2142 Int_t charw = fNumericEntry->GetCharWidth("0123456789");
2143 Int_t digits = (30*w - 240 -20*h)/(3*charw) + 3;
2144
2145 // for time format
2146 Int_t hour, min, sec;
2147 GetTime(hour, min, sec);
2148
2149 // for date format
2150 Int_t yy, mm, dd;
2151 GetDate(yy, mm, dd);
2152
2153 out << " TGNumberEntry *";
2154 out << GetName() << " = new TGNumberEntry(" << fParent->GetName() << ", (Double_t) ";
2155 switch (GetNumStyle()){
2156 case kNESInteger:
2157 out << GetIntNumber() << "," << digits << "," << WidgetId()
2158 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2159 break;
2160 case kNESRealOne:
2161 out << GetNumber() << "," << digits << "," << WidgetId()
2162 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2163 break;
2164 case kNESRealTwo:
2165 out << GetNumber() << "," << digits << "," << WidgetId()
2166 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2167 break;
2168 case kNESRealThree:
2169 out << GetNumber() << "," << digits << "," << WidgetId()
2170 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2171 break;
2172 case kNESRealFour:
2173 out << GetNumber() << "," << digits << "," << WidgetId()
2174 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2175 break;
2176 case kNESReal:
2177 out << GetNumber() << "," << digits << "," << WidgetId()
2178 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2179 break;
2180 case kNESDegree:
2181 out << GetIntNumber() << "," << digits << "," << WidgetId()
2182 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2183 break;
2184 case kNESMinSec:
2185 out << min*60 + sec << "," << digits << "," << WidgetId()
2186 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2187 break;
2188 case kNESHourMin:
2189 out << hour*60 + min << "," << digits << "," << WidgetId()
2190 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2191 break;
2192 case kNESHourMinSec:
2193 out << hour*3600 + min*60 + sec << "," << digits << "," << WidgetId()
2194 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2195 break;
2196 case kNESDayMYear:
2197 out << yy << mm << dd << "," << digits << "," << WidgetId()
2198 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2199 break;
2200 case kNESMDayYear:
2201 out << yy << mm << dd << "," << digits << "," << WidgetId()
2202 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2203 break;
2204 case kNESHex:
2205 { char hex[256];
2207 IntToHexStr(hex, l);
2208 std::ios::fmtflags f = out.flags(); // store flags
2209 out << "0x" << std::hex << "U," << digits << "," << WidgetId()
2210 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2211 out.flags( f ); // restore flags (reset std::hex)
2212 break;
2213 }
2214 }
2215 if (GetNumMax() ==1) {
2216 if (GetNumMin() == 0) {
2217 if (GetNumLimits() == kNELNoLimits) {
2218 if (GetNumAttr() == kNEAAnyNumber) {
2219 out << ");" << std::endl;
2220 } else {
2221 out << ",(TGNumberFormat::EAttribute) " << GetNumAttr() << ");" << std::endl;
2222 }
2223 } else {
2224 out << ",(TGNumberFormat::EAttribute) " << GetNumAttr()
2225 << ",(TGNumberFormat::ELimit) " << GetNumLimits() << ");" << std::endl;
2226 }
2227 } else {
2228 out << ",(TGNumberFormat::EAttribute) " << GetNumAttr()
2229 << ",(TGNumberFormat::ELimit) " << GetNumLimits()
2230 << "," << GetNumMin() << ");" << std::endl;
2231 }
2232 } else {
2233 out << ",(TGNumberFormat::EAttribute) " << GetNumAttr()
2234 << ",(TGNumberFormat::ELimit) " << GetNumLimits()
2235 << "," << GetNumMin() << "," << GetNumMax() << ");" << std::endl;
2236 }
2237 if (option && strstr(option, "keep_names"))
2238 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
2240 out << " " << GetName() << "->SetState(kFALSE);" << std::endl;
2241
2243 if (tip) {
2244 TString tiptext = tip->GetText()->GetString();
2245 tiptext.ReplaceAll("\n", "\\n");
2246 out << " ";
2247 out << GetName() << "->GetNumberEntry()->SetToolTipText(" << quote
2248 << tiptext << quote << ");" << std::endl;
2249 }
2250}
2251
2252////////////////////////////////////////////////////////////////////////////////
2253/// Save a number entry widget as a C++ statement(s) on output stream out.
2254
2255void TGNumberEntryField::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
2256{
2257 char quote = '"';
2258
2259 // for time format
2260 Int_t hour, min, sec;
2261 GetTime(hour, min, sec);
2262
2263 // for date format
2264 Int_t yy, mm, dd;
2265 GetDate(yy, mm, dd);
2266
2267 out << " TGNumberEntryField *";
2268 out << GetName() << " = new TGNumberEntryField(" << fParent->GetName()
2269 << ", " << WidgetId() << ", (Double_t) ";
2270 switch (GetNumStyle()){
2271 case kNESInteger:
2272 out << GetIntNumber()
2273 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2274 break;
2275 case kNESRealOne:
2276 out << GetNumber()
2277 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2278 break;
2279 case kNESRealTwo:
2280 out << GetNumber()
2281 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2282 break;
2283 case kNESRealThree:
2284 out << GetNumber()
2285 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2286 break;
2287 case kNESRealFour:
2288 out << GetNumber()
2289 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2290 break;
2291 case kNESReal:
2292 out << GetNumber()
2293 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2294 break;
2295 case kNESDegree:
2296 out << GetIntNumber()
2297 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2298 break;
2299 case kNESMinSec:
2300 out << min*60 + sec
2301 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2302 break;
2303 case kNESHourMin:
2304 out << hour*60 + min
2305 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2306 break;
2307 case kNESHourMinSec:
2308 out << hour*3600 + min*60 + sec
2309 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2310 break;
2311 case kNESDayMYear:
2312 out << yy << mm << dd
2313 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2314 break;
2315 case kNESMDayYear:
2316 out << yy << mm << dd
2317 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2318 break;
2319 case kNESHex:
2320 { char hex[256];
2322 IntToHexStr(hex, l);
2323 std::ios::fmtflags f = out.flags(); // store flags
2324 out << "0x" << std::hex << "U"
2325 << ",(TGNumberFormat::EStyle) " << GetNumStyle();
2326 out.flags( f ); // restore flags (reset std::hex)
2327 break;
2328 }
2329 }
2330 if (GetNumMax() ==1) {
2331 if (GetNumMin() == 0) {
2332 if (GetNumLimits() == kNELNoLimits) {
2333 if (GetNumAttr() == kNEAAnyNumber) {
2334 out << ");" << std::endl;
2335 } else {
2336 out << ",(TGNumberFormat::EAttribute) " << GetNumAttr() << ");" << std::endl;
2337 }
2338 } else {
2339 out << ",(TGNumberFormat::EAttribute) " << GetNumAttr()
2340 << ",(TGNumberFormat::ELimit) " << GetNumLimits() << ");" << std::endl;
2341 }
2342 } else {
2343 out << ",(TGNumberFormat::EAttribute) " << GetNumAttr()
2344 << ",(TGNumberFormat::ELimit) " << GetNumLimits()
2345 << "," << GetNumMin() << ");" << std::endl;
2346 }
2347 } else {
2348 out << ",(TGNumberFormat::EAttribute) " << GetNumAttr()
2349 << ",(TGNumberFormat::ELimit) " << GetNumLimits()
2350 << "," << GetNumMin() << "," << GetNumMax() << ");" << std::endl;
2351 }
2352 if (option && strstr(option, "keep_names"))
2353 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
2354 if (!IsEnabled())
2355 out << " " << GetName() << "->SetState(kFALSE);" << std::endl;
2356
2357 out << " " << GetName() << "->Resize("<< GetWidth() << "," << GetName()
2358 << "->GetDefaultHeight());" << std::endl;
2359
2360 TGToolTip *tip = GetToolTip();
2361 if (tip) {
2362 TString tiptext = tip->GetText()->GetString();
2363 tiptext.ReplaceAll("\n", "\\n");
2364 out << " ";
2365 out << GetName() << "->SetToolTipText(" << quote
2366 << tiptext << quote << ");" << std::endl;
2367 }
2368}
@ kButtonPress
Definition GuiTypes.h:60
@ kFocusOut
Definition GuiTypes.h:61
const Mask_t kKeyMod1Mask
typically the Alt key
Definition GuiTypes.h:198
@ kNotifyNormal
Definition GuiTypes.h:219
@ kNotifyPointer
Definition GuiTypes.h:220
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:38
const Mask_t kKeyShiftMask
Definition GuiTypes.h:195
const Mask_t kKeyControlMask
Definition GuiTypes.h:197
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
EKeySym
Definition KeySymbols.h:25
@ kKey_Down
Definition KeySymbols.h:43
@ kKey_Up
Definition KeySymbols.h:41
@ kKey_Delete
Definition KeySymbols.h:33
@ kKey_Backspace
Definition KeySymbols.h:29
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
constexpr Long_t kMaxLong
Definition RtypesCore.h:116
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
constexpr Int_t kMaxInt
Definition RtypesCore.h:112
long Longptr_t
Definition RtypesCore.h:82
long Long_t
Definition RtypesCore.h:54
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:80
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
unsigned long ULong_t
Definition RtypesCore.h:55
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:197
@ kButtonDown
Definition TGButton.h:54
@ kButtonDisabled
Definition TGButton.h:56
@ kButtonUp
Definition TGButton.h:53
#define gClient
Definition TGClient.h:157
static char * DIntToStr(char *text, Long_t l, Bool_t Sec, char Del)
const Double_t kEpsilon
static void IncreaseDate(Long_t &l, TGNumberFormat::EStepSize step, Int_t sign)
Change year/month/day format.
ERealStyle
@ kRSFrac
@ kRSInt
@ kRSExpo
@ kRSFracExpo
static void IncreaseReal(RealInfo_t &ri, Double_t mag, Bool_t logstep, TGNumberFormat::ELimit limits=TGNumberFormat::kNELNoLimits, Double_t min=0, Double_t max=1)
Convert to double format.
static Long_t Truncate(Double_t x)
static char * RealToStr(char *text, const RealInfo_t &ri)
static Long_t TranslateToNum(const char *text, TGNumberFormat::EStyle style, RealInfo_t &ri)
Translate a string to a number value.
static Bool_t IsGoodChar(char c, TGNumberFormat::EStyle style, TGNumberFormat::EAttribute attr)
static char * MIntToStr(char *text, Long_t l, Int_t digits)
static char * IntToHexStr(char *text, ULong_t l)
static char * TranslateToStr(char *text, Long_t l, TGNumberFormat::EStyle style, const RealInfo_t &ri)
Translate a number value to a string.
const Int_t kDays[13]
static char * EliminateGarbage(char *text, TGNumberFormat::EStyle style, TGNumberFormat::EAttribute attr)
static Long_t Round(Double_t x)
static void GetNumbers(const char *s, Int_t &Sign, Long_t &n1, Int_t maxd1, Long_t &n2, Int_t maxd2, Long_t &n3, Int_t maxd3, const char *Delimiters)
static char * StrInt(char *text, Long_t i, Int_t digits)
static ULong_t HexStrToInt(const char *s)
static Long_t GetSignificant(Long_t l, Int_t Max)
static void AppendFracZero(char *text, Int_t digits)
static void CheckMinMax(Long_t &l, TGNumberFormat::EStyle style, TGNumberFormat::ELimit limits, Double_t min, Double_t max)
Check min/max limits for the set value.
static Long_t IntStr(const char *text)
static Double_t RealToDouble(const RealInfo_t ri)
Convert to double format.
static TString StringInt(Long_t i, Int_t digits)
static Double_t StrToReal(const char *text, RealInfo_t &ri)
static Bool_t IsLeapYear(Int_t year)
static Long_t MakeDateNumber(const char *, Long_t Day, Long_t Month, Long_t Year)
Create a number entry with year/month/day information.
@ kTextRight
Definition TGWidget.h:24
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Option_t Option_t style
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t button
Option_t Option_t TPoint TPoint const char text
R__EXTERN TSystem * gSystem
Definition TSystem.h:560
#define gVirtualX
Definition TVirtualX.h:338
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
Int_t GET_MSG(Long_t val)
@ kC_COMMAND
@ kCM_BUTTON
Int_t GET_SUBMSG(Long_t val)
#define snprintf
Definition civetweb.c:1540
virtual EButtonState GetState() const
Definition TGButton.h:112
EButtonState fState
button state
Definition TGButton.h:75
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set button state.
Definition TGButton.cxx:235
TGToolTip * fTip
tool tip associated with button
Definition TGButton.h:79
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition TGClient.cxx:234
const TGPicture * GetPicture(const char *name)
Get picture from the picture pool.
Definition TGClient.cxx:289
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:287
TGLayoutManager * fLayoutManager
layout manager
Definition TGFrame.h:291
virtual void SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition TGFrame.cxx:1000
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition TGFrame.cxx:967
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0) override
Move and/or resize the frame.
Definition TGFrame.cxx:629
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
virtual UInt_t GetDefaultHeight() const
Definition TGFrame.h:191
TGDimension GetSize() const
Definition TGFrame.h:230
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
Definition TGFrame.cxx:645
UInt_t GetHeight() const
Definition TGFrame.h:225
UInt_t GetWidth() const
Definition TGFrame.h:224
Frame layout manager.
Definition TGLayout.h:135
TClass * IsA() const override
Definition TGLayout.h:149
virtual void SetHexNumber(ULong_t val, Bool_t emit=kTRUE)
Set the numeric value (hex format).
ELimit fNumLimits
Limit attributes.
virtual void InvalidInput(const char *instr)
virtual Double_t GetNumMin() const
Get the lower limit.
Bool_t fNeedsVerification
Needs verification of input.
virtual void SetFormat(EStyle style, EAttribute attr=kNEAAnyNumber)
Set the numerical format.
virtual void SetDate(Int_t year, Int_t month, Int_t day, Bool_t emit=kTRUE)
Set the numeric value (date format).
virtual Long_t GetIntNumber() const
Get the numeric value (integer representation).
virtual void SetNumber(Double_t val, Bool_t emit=kTRUE)
Set the numeric value (floating point representation).
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
EStyle fNumStyle
Number style.
virtual Bool_t IsLogStep() const
Is log step enabled?
Bool_t HandleFocusChange(Event_t *event) override
Handle focus change.
void SetState(Bool_t state) override
Set the active state.
virtual EStyle GetNumStyle() const
Get the numerical style.
void ReturnPressed() override
Return was pressed.
virtual Double_t GetNumMax() const
Get the upper limit.
virtual void GetDate(Int_t &year, Int_t &month, Int_t &day) const
Get the numeric value (date format).
void TextChanged(const char *text=nullptr) override
Text has changed message.
void SavePrimitive(std::ostream &out, Option_t *="") override
Save a number entry widget as a C++ statement(s) on output stream out.
virtual void IncreaseNumber(EStepSize step=kNSSSmall, Int_t sign=1, Bool_t logstep=kFALSE)
Increase the number value.
virtual ULong_t GetHexNumber() const
Get the numeric value (hex format).
virtual void SetIntNumber(Long_t val, Bool_t emit=kTRUE)
Set the numeric value (integer representation).
Bool_t HandleKey(Event_t *event) override
Handle keys.
virtual void SetLimits(ELimit limits=kNELNoLimits, Double_t min=0, Double_t max=1)
Set the numerical limits.
virtual void GetTime(Int_t &hour, Int_t &min, Int_t &sec) const
Get the numeric value (time format).
virtual void SetLogStep(Bool_t on=kTRUE)
Set logarithmic steps.
virtual EAttribute GetNumAttr() const
Get the numerical attribute.
TGNumberEntryField(const TGWindow *p, Int_t id, Double_t val, GContext_t norm, FontStruct_t font=GetDefaultFontStruct(), UInt_t option=kSunkenFrame|kDoubleBorder, Pixel_t back=GetWhitePixel())
Constructs a number entry field.
void SetText(const char *text, Bool_t emit=kTRUE) override
Set the value (text format).
EAttribute fNumAttr
Number attribute.
Double_t fNumMin
Lower limit.
virtual Int_t GetCharWidth(const char *text="0") const
Get the text width in pixels.
virtual void SetTime(Int_t hour, Int_t min, Int_t sec, Bool_t emit=kTRUE)
Set the numeric value (time format).
Bool_t fStepLog
Logarithmic steps for increase?
Double_t fNumMax
Upper limit.
void Layout() override
Layout.
virtual ELimit GetNumLimits() const
Get the numerical limit attribute.
TGNumberEntry * fBox
TGDimension GetDefaultSize() const override
Return the default size of the numeric control box.
void Layout() override
Layout the internal GUI elements in use.
static TClass * Class()
TGNumberEntry is a number entry input widget with up/down buttons.
TGButton * fButtonDown
Button for decreasing value.
virtual Double_t GetNumMax() const
virtual EStyle GetNumStyle() const
Bool_t fButtonToNum
Send button messages to parent rather than number entry field.
virtual ULong_t GetHexNumber() const
virtual ~TGNumberEntry()
Destructs a numeric entry widget.
virtual void SetButtonToNum(Bool_t state)
Send button messages to the number field (true) or parent widget (false).
virtual void ValueSet(Long_t val)
Emit ValueSet(Long_t) signal.
TGNumberEntryField * GetNumberEntry() const
Get the number entry field.
const TGPicture * fPicUp
Up arrow.
virtual void SetState(Bool_t enable=kTRUE)
Set the active state.
TGNumberEntry(const TGNumberEntry &)=delete
virtual ELimit GetNumLimits() const
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override
Process the up/down button messages.
virtual void SetLogStep(Bool_t on=kTRUE)
Set log steps.
const TGPicture * fPicDown
Down arrow.
void SavePrimitive(std::ostream &out, Option_t *="") override
Save a number entry widget as a C++ statement(s) on output stream out.
virtual void ValueChanged(Long_t val)
Emit ValueChanged(Long_t) signal.
TGLayoutManager * GetLayoutManager() const override
Return layout manager.
virtual void GetDate(Int_t &year, Int_t &month, Int_t &day) const
void Associate(const TGWindow *w) override
Make w the window that will receive the generated messages.
TGButton * GetButtonDown() const
Get the down button.
virtual Long_t GetIntNumber() const
virtual EAttribute GetNumAttr() const
virtual void Modified()
Emit Modified() signal.
virtual Double_t GetNumMin() const
TGNumberEntryField * fNumericEntry
Number text entry field.
virtual Double_t GetNumber() const
TGButton * fButtonUp
Button for increasing value.
TGButton * GetButtonUp() const
Get the up button.
virtual void GetTime(Int_t &hour, Int_t &min, Int_t &sec) const
@ kNEAPositive
Positive number.
@ kNEANonNegative
Non-negative number.
@ kNEAAnyNumber
Attributes of number entry field.
@ kNESRealOne
Fixed fraction real, one digit.
@ kNESHourMin
Hour:minutes.
@ kNESDegree
Degree.
@ kNESMDayYear
Month/day/year.
@ kNESReal
Real number.
@ kNESRealThree
Fixed fraction real, three digit.
@ kNESInteger
Style of number entry field.
@ kNESRealFour
Fixed fraction real, four digit.
@ kNESDayMYear
Day/month/year.
@ kNESRealTwo
Fixed fraction real, two digit.
@ kNESHourMinSec
Hour:minute:seconds.
@ kNESMinSec
Minute:seconds.
@ kNSSHuge
Huge step.
@ kNSSMedium
Medium step.
@ kNSSLarge
Large step.
@ kNSSSmall
Step for number entry field increase.
@ kNELNoLimits
Limit selection of number entry field.
@ kNELLimitMax
Upper limit only.
@ kNELLimitMin
Lower limit only.
@ kNELLimitMinMax
Both lower and upper limits.
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Yield an action as soon as it is clicked.
Definition TGButton.h:228
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition TGPicture.h:25
TGNumberFormat::EStepSize fStep
void FireButton()
Process messages for fire button.
TGRepeatFireButton(const TGWindow *p, const TGPicture *pic, Int_t id, Bool_t logstep)
Bool_t IsEditableParent()
Return kTRUE if one of the parents is in edit mode.
TRepeatTimer * fTimer
Bool_t HandleButton(Event_t *event) override
Handle messages for number entry widget according to the user input.
virtual void SetLogStep(Bool_t on=kTRUE)
const char * GetString() const
Definition TGString.h:30
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
const char * GetString() const
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
virtual void SetState(Bool_t state)
Set state of widget. If kTRUE=enabled, kFALSE=disabled.
Bool_t HandleKey(Event_t *event) override
The key press event handler converts a key press to some line editor action.
TGTextBuffer * GetBuffer() const
const char * GetText() const
virtual void SetAlignment(ETextJustification mode=kTextLeft)
Sets the alignment of the text entry.
virtual TGToolTip * GetToolTip() const
ETextJustification GetAlignment() const
virtual void ReturnPressed()
This signal is emitted when the return or enter key is pressed.
Bool_t HandleFocusChange(Event_t *event) override
Handle focus change event in text entry widget.
virtual void SetText(const char *text, Bool_t emit=kTRUE)
Sets text entry to text, clears the selection and moves the cursor to the end of the line.
FontStruct_t fFontStruct
text font
Definition TGTextEntry.h:41
void End(Bool_t mark=kFALSE)
Moves the text cursor to the right end of the line.
virtual void TextChanged(const char *text=nullptr)
This signal is emitted every time the text has changed.
void Home(Bool_t mark=kFALSE)
Moves the text cursor to the left end of the line.
A tooltip can be a one or multiple lines help text that is displayed in a window when the mouse curso...
Definition TGToolTip.h:24
void Hide()
Hide tool tip window.
const TGString * GetText() const
Get the tool tip text.
Int_t fWidgetId
the widget id (used for event processing)
Definition TGWidget.h:46
virtual void Associate(const TGWindow *w)
Definition TGWidget.h:72
const TGWindow * fMsgWindow
window which handles widget events
Definition TGWidget.h:48
Bool_t IsEnabled() const
Definition TGWidget.h:69
Int_t WidgetId() const
Definition TGWidget.h:68
ROOT GUI Window base class.
Definition TGWindow.h:23
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
@ kEditDisableHeight
window height cannot be edited
Definition TGWindow.h:62
@ kEditDisableLayout
window layout cannot be edited
Definition TGWindow.h:60
@ kEditDisableGrab
window grab cannot be edited
Definition TGWindow.h:59
@ kEditDisable
disable edit of this window
Definition TGWindow.h:57
virtual Bool_t IsEditable() const
Definition TGWindow.h:111
const TGWindow * GetParent() const
Definition TGWindow.h:83
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:336
UInt_t fEditDisabled
flags used for "guibuilding"
Definition TGWindow.h:32
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition TQObject.cxx:869
TRepeatTimer(TGRepeatFireButton *button, Long_t ms)
Bool_t Notify() override
Notify when timer times out and reset the timer.
TGRepeatFireButton * fButton
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:421
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition TSystem.cxx:474
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
TTime fTime
Definition TTimer.h:54
void Reset()
Reset the timer.
Definition TTimer.cxx:159
void SetTime(Long_t milliSec)
Definition TTimer.h:91
void Remove() override
Definition TTimer.h:86
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:719
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
Event structure.
Definition GuiTypes.h:174
ERealStyle fStyle
TLine l
Definition textangle.C:4