Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGTextEntry.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Fons Rademakers 08/01/98
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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 This source is based on Xclass95, a Win95-looking GUI toolkit.
14 Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
15
16 Xclass95 is free software; you can redistribute it and/or
17 modify it under the terms of the GNU Library General Public
18 License as published by the Free Software Foundation; either
19 version 2 of the License, or (at your option) any later version.
20
21**************************************************************************/
22
23
24/** \class TGTextEntry
25 \ingroup guiwidgets
26
27A TGTextEntry is a one line text input widget.
28
29Changing text in the text entry widget will generate the event:
30kC_TEXTENTRY, kTE_TEXTCHANGED, widget id, 0.
31Hitting the enter key will generate:
32kC_TEXTENTRY, kTE_ENTER, widget id, 0.
33Hitting the tab key will generate:
34kC_TEXTENTRY, kTE_TAB, widget id, 0.
35
36This widget has the behaviour e.g. of the "Location" field in
37web browsers. That includes handling Control/Shift key modifiers and
38scrolling the text.
39
40enum TGTextEntry::EEchoMode
41
42This enum type describes the ways in which TGTextEntry can display
43its contents. The currently defined values are:
44
45<ul>
46<li> kNormal - display characters as they are entered. This is the default.
47<li> kNoEcho - do not display anything.
48<li> kPassword - display asterisks instead of the characters actually entered.
49</ul>
50
51See also SetEchoMode(), GetEchoMode().
52
53enum TGTextEntry::EInsertMode
54
55This enum type describes the way how typed characters are
56inserted in the text entry. This mode is switched by "Insert" key.
57
58<ul>
59<li> kInsert - typed character are inserted (cursor has shape of short line).
60<li> kReplace - typed characters substitute already typed ones
61 (cursor has the shape of filled rectangle).
62</ul>
63
64enum TGWidget::ETextJustification
65
66This enum type (defined in TGWidget.h) describes the text alignment modes.
67These modes are valid until text fits the frame width
68
69<ul>
70<li> kTextLeft - left-side text alignment
71<li> kTextRight - right-side text alignment
72<li> kTextCenterX - center text alignment
73</ul>
74
75The key press event handler converts a key press to some line editor action.
76Here are the default key bindings:
77
78
79<ul>
80<li><i> Left Arrow </i>
81 Move the cursor one character leftwards.
82 Scroll the text when cursor is out of frame.
83<li><i> Right Arrow </i>
84 Move the cursor one character rightwards
85 Scroll the text when cursor is out of frame.
86<li><i> Backspace </i>
87 Deletes the character on the left side of the text cursor and moves the
88 cursor one position to the left. If a text has been marked by the user
89 (e.g. by clicking and dragging) the cursor will be put at the beginning
90 of the marked text and the marked text will be removed.
91<li><i> Home </i>
92 Moves the text cursor to the left end of the line. If mark is TRUE text
93 will be marked towards the first position, if not any marked text will
94 be unmarked if the cursor is moved.
95<li><i> End </i>
96 Moves the text cursor to the right end of the line. If mark is TRUE text
97 will be marked towards the last position, if not any marked text will
98 be unmarked if the cursor is moved.
99<li><i> Delete </i>
100 Deletes the character on the right side of the text cursor. If a text
101 has been marked by the user (e.g. by clicking and dragging) the cursor
102 will be put at the beginning of the marked text and the marked text will
103 be removed.
104<li><i> Insert </i>
105 Switches character insert mode.
106<li><i> Shift - Left Arrow </i>
107 Mark text one character leftwards
108<li><i> Shift - Right Arrow </i>
109 Mark text one character rightwards
110<li><i> Control - Left Arrow </i>
111 Move the cursor one word leftwards
112<li><i> Control - Right Arrow </i>
113 Move the cursor one word rightwards.
114<li><i> Control - Shift - Left Arrow </i>
115 Mark text one word leftwards
116<li><i> Control - Shift - Right Arrow </i>
117 Mark text one word rightwards
118<li><i> Control-A </i>
119 Move the cursor to the beginning of the line
120<li><i> Control-B </i>
121 Move the cursor one character leftwards
122<li><i> Control-C </i>
123 Copy the marked text to the clipboard.
124<li><i> Control-D </i>
125 Delete the character to the right of the cursor
126<li><i> Control-E </i>
127 Move the cursor to the end of the line
128<li><i> Control-F </i>
129 Move the cursor one character rightwards
130<li><i> Control-H </i>
131 Delete the character to the left of the cursor
132<li><i> Control-K </i>
133 Delete marked text if any or delete all
134 characters to the right of the cursor
135<li><i> Control-U </i>
136 Delete all characters on the line
137<li><i> Control-V </i>
138 Paste the clipboard text into line edit.
139<li><i> Control-X </i>
140 Cut the marked text, copy to clipboard.
141<li><i> Control-Y </i>
142 Paste the clipboard text into line edit.
143</ul>
144All other keys with valid ASCII codes insert themselves into the line.
145*/
146
147
148//******************* TGTextEntry signals *************************************
149//______________________________________________________________________________
150// TGTextEntry::ReturnPressed()
151//
152// This signal is emitted when the return or enter key is pressed.
153//
154//______________________________________________________________________________
155// TGTextEntry::TabPressed()
156//
157// This signal is emitted when the <TAB> key is pressed.
158// Use for changing focus.
159//
160//______________________________________________________________________________
161// TGTextEntry::ShiftTabPressed()
162//
163// This signal is emitted when the <SHIFT> and <TAB> keys are pressed.
164// Use for changing focus in reverse direction.
165//
166//______________________________________________________________________________
167// TGTextEntry::TextChanged(const char *text)
168//
169// This signal is emitted every time the text has changed.
170// The argument is the new text.
171//
172//______________________________________________________________________________
173// TGTextEntry::CursorOutLeft()
174//
175// This signal is emitted when cursor is going out of left side.
176//
177//______________________________________________________________________________
178// TGTextEntry::CursorOutRight()
179//
180// This signal is emitted when cursor is going out of right side.
181//
182//______________________________________________________________________________
183// TGTextEntry::CursorOutUp()
184//
185// This signal is emitted when cursor is going out of upper side.
186//
187//______________________________________________________________________________
188// TGTextEntry::CursorOutDown()
189//
190// This signal is emitted when cursor is going out of bottom side.
191//
192//______________________________________________________________________________
193// TGTextEntry::DoubleClicked()
194//
195// This signal is emitted when widget is double clicked.
196
197
198#include "TGTextEntry.h"
199#include "TGResourcePool.h"
200#include "TGToolTip.h"
201#include "TSystem.h"
202#include "TTimer.h"
203#include "TColor.h"
204#include "KeySymbols.h"
205#include "TClass.h"
206#include "TVirtualX.h"
207#include "strlcpy.h"
208
209#include <iostream>
210
211
217
219
220////////////////////////////////////////////////////////////////////////////////
221
222class TBlinkTimer : public TTimer {
223private:
225public:
227 Bool_t Notify() override;
228};
229
230////////////////////////////////////////////////////////////////////////////////
231/// Notify when timer times out and reset the timer.
232
234{
236 Reset();
237 return kFALSE;
238}
239
240
242
243////////////////////////////////////////////////////////////////////////////////
244/// Create a text entry widget. It will adopt the TGTextBuffer object
245/// (i.e. the text buffer will be deleted by the text entry widget).
246
248 GContext_t norm, FontStruct_t font, UInt_t options,
249 Pixel_t back) :
250 TGFrame(p, 1, 1, options | kOwnBackground, back)
251{
252 TGGC *normgc = fClient->GetResourcePool()->GetGCPool()->FindGC(norm);
253
254 fWidgetId = id;
255 fMsgWindow = p;
256 if (normgc)
257 fNormGC = *normgc;
258 else
260 fFontStruct = font;
261 fText = text;
262
263 Init();
264}
265
266////////////////////////////////////////////////////////////////////////////////
267/// Simple text entry constructor.
268
269TGTextEntry::TGTextEntry(const TGWindow *parent, const char *text, Int_t id) :
270 TGFrame(parent, 1, 1, kSunkenFrame | kDoubleBorder | kOwnBackground, fgWhitePixel)
271{
272 fWidgetId = id;
273 fMsgWindow = parent;
276 fText = new TGTextBuffer();
277 fText->AddText(0, !text && !parent ? GetName() : text);
278
279 Init(); // default initialization
280}
281
282////////////////////////////////////////////////////////////////////////////////
283/// Simple test entry constructor. Notice TString argument comes before the
284/// parent argument (to make this ctor different from the first one taking a
285/// const char*).
286
287TGTextEntry::TGTextEntry(const TString &contents, const TGWindow *parent, Int_t id) :
288 TGFrame(parent, 1, 1, kSunkenFrame | kDoubleBorder | kOwnBackground, fgWhitePixel)
289{
290 fWidgetId = id;
291 fMsgWindow = parent;
294 fText = new TGTextBuffer();
295 fText->AddText(0, contents.Data());
296
297 Init(); // default initialization
298}
299
300////////////////////////////////////////////////////////////////////////////////
301/// Delete a text entry widget.
302
304{
305 delete fText;
306 delete fCurBlink;
307 delete fTip;
308
309 if (this == gBlinkingEntry) gBlinkingEntry = 0;
310}
311
312////////////////////////////////////////////////////////////////////////////////
313/// Do default initialization.
314
316{
320
321 fOffset = 0;
322 // Set default maximum length to 4096. Can be changed with SetMaxLength()
323 fMaxLen = 4096;
325 fEdited = kFALSE;
329 fDefWidth = fDefHeight = 0;
330
331 int tw, max_ascent, max_descent;
332 tw = gVirtualX->TextWidth(fFontStruct, GetText(), fText->GetTextLength());
333
334 if (tw < 1) {
335 TString dummy('w', fText->GetBufferLength());
336 tw = gVirtualX->TextWidth(fFontStruct, dummy.Data(), dummy.Length());
337 }
338 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
339 Resize(tw + 8, max_ascent + max_descent + 7);
340
341 Int_t offset = IsFrameDrawn() ? 4 : 0;
342 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
343 offset = 2;
344 fCursorX = offset ;
347 fCurBlink = 0;
348 fTip = 0;
350
352
353 gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier,
356
359
362 wattr.fBitGravity = 1; // NorthWestGravity
363 wattr.fWinGravity = 1;
364 gVirtualX->ChangeWindowAttributes(fId, &wattr);
365
369}
370
371////////////////////////////////////////////////////////////////////////////////
372/// Return the default / minimal size of the widget.
373
375{
378 return TGDimension(w, h);
379}
380
381////////////////////////////////////////////////////////////////////////////////
382/// Set the default / minimal size of the widget.
383
385{
386 fDefWidth = w;
387 fDefHeight = h;
388}
389
390////////////////////////////////////////////////////////////////////////////////
391/// This signal is emitted when the return or enter key is pressed.
392
394{
397
398 Emit("ReturnPressed()");
399}
400
401////////////////////////////////////////////////////////////////////////////////
402/// This signal is emitted when `SHIFT` and `TAB` keys are pressed.
403
405{
406 Emit("ShiftTabPressed()");
407}
408
409////////////////////////////////////////////////////////////////////////////////
410/// This signal is emitted when the `<TAB>` key is pressed.
411
413{
416
417 Emit("TabPressed()");
418}
419
420////////////////////////////////////////////////////////////////////////////////
421/// This signal is emitted every time the text has changed.
422
423void TGTextEntry::TextChanged(const char *)
424{
427
428 Emit("TextChanged(char*)", GetText()); // The argument is the new text.
429}
430
431////////////////////////////////////////////////////////////////////////////////
432/// This signal is emitted when cursor is going out of left side.
433
435{
436 Emit("CursorOutLeft()");
437}
438
439////////////////////////////////////////////////////////////////////////////////
440/// This signal is emitted when cursor is going out of right side.
441
443{
444 Emit("CursorOutRight()");
445}
446
447////////////////////////////////////////////////////////////////////////////////
448/// This signal is emitted when cursor is going out of upper side.
449
451{
452 Emit("CursorOutUp()");
453}
454
455////////////////////////////////////////////////////////////////////////////////
456/// This signal is emitted when cursor is going out of bottom side.
457
459{
460 Emit("CursorOutDown()");
461}
462
463////////////////////////////////////////////////////////////////////////////////
464/// This signal is emitted when widget is double clicked.
465
467{
468 Emit("DoubleClicked()");
469}
470
471////////////////////////////////////////////////////////////////////////////////
472/// Returns the text that's currently displayed. This is normally
473/// the same as GetText(), but can be e.g.
474/// "*****" if EEchoMode is kPassword or
475/// "" if it is kNoEcho.
476
478{
479 TString res;
480
481 switch (GetEchoMode()) {
482 case kNormal:
483 res = GetText();
484 break;
485 case kNoEcho:
486 res = "";
487 break;
488 case kPassword:
489 res.Prepend('*', fText->GetTextLength()); // fill with '*'
490 break;
491 }
492 return res;
493}
494
495////////////////////////////////////////////////////////////////////////////////
496/// Set state of widget. If kTRUE=enabled, kFALSE=disabled.
497
499{
500 if (state) {
503 } else {
506 fCursorOn = kFALSE; // remove the cursor when disabling the widget
507 if (fCurBlink) fCurBlink->Remove();
508 }
509 fClient->NeedRedraw(this);
510}
511
512////////////////////////////////////////////////////////////////////////////////
513/// Returns the index of the character to whose left edge xcoord is closest.
514
516{
517 int tw, ix, up, down, len;
518
519 // check for out of boundaries first...
520 TString dt = GetDisplayText();
521 len = dt.Length();
522 tw = gVirtualX->TextWidth(fFontStruct, dt.Data(), len);
523 if (xcoord < 0) return 0;
524 if (xcoord > tw) return len; // len-1
525
526 // do a binary approximation
527 up = len; //-1
528 down = 0;
529 while (up-down > 1) {
530 ix = (up+down) >> 1;
531 tw = gVirtualX->TextWidth(fFontStruct, fText->GetString(), ix);
532 if (tw > xcoord)
533 up = ix;
534 else
535 down = ix;
536 if (tw == xcoord) break;
537 }
538 ix = down;
539
540 // safety check...
541 ix = TMath::Max(ix, 0);
542 ix = TMath::Min(ix, len); // len-1
543
544 return ix;
545}
546
547////////////////////////////////////////////////////////////////////////////////
548/// Sets the text entry to draw itself inside a two-pixel frame if
549/// enable is kTRUE, and to draw itself without any frame if enable is
550/// kFALSE. The default is kTRUE.
551
553{
554 if (fFrameDrawn == enable) return;
555
556 fFrameDrawn = enable;
557 fClient->NeedRedraw(this);
558 // ChangedBy("SetFrameDrawn"); // emit signal ChangedBy
559}
560
561////////////////////////////////////////////////////////////////////////////////
562/// Sets the alignment of the text entry.
563/// Possible values are kTextLeft(default), kTextRight, kTextCenterX.
564/// See also GetAlignment().
565
567{
568 if ((mode == kTextRight ||
569 mode == kTextCenterX ||
570 mode == kTextLeft)) {
571
574 wattr.fWinGravity = 1;
575
576 if (mode == kTextLeft) {
577 wattr.fBitGravity = 1;
578 } else if (mode == kTextRight) {
579 wattr.fBitGravity = 3;
580 } else {
581 wattr.fBitGravity = 5;
582 }
583
584 gVirtualX->ChangeWindowAttributes(fId, &wattr);
585
587 UpdateOffset();
588 fClient->NeedRedraw(this);
589 // ChangedBy("SetAlignment"); // emit signal ChangedBy
590 }
591}
592
593////////////////////////////////////////////////////////////////////////////////
594/// Sets the mode how characters are entered to the text entry.
595
597{
598 if (fInsertMode == mode) return;
599
601 fClient->NeedRedraw(this);
602 // ChangedBy("SetInsertMode"); // emit signal ChangedBy
603}
604
605////////////////////////////////////////////////////////////////////////////////
606/// Sets text entry to text, clears the selection and moves
607/// the cursor to the end of the line.
608/// If necessary the text is truncated to fit MaxLength().
609/// See also GetText().
610
611void TGTextEntry::SetText(const char *text, Bool_t emit)
612{
613 TString oldText(GetText());
614
615 fText->Clear();
616 fText->AddText(0, text); // new text
617
618 Int_t dif = fText->GetTextLength() - fMaxLen;
619 if (dif > 0) fText->RemoveText(fMaxLen, dif); // truncate
620
621 End(kFALSE);
622 if (oldText != GetText()) {
623 if (emit)
624 TextChanged(); // emit signal
625 fClient->NeedRedraw(this);
626 }
627}
628
629////////////////////////////////////////////////////////////////////////////////
630/// Set the maximum length of the text in the editor. If the text is
631/// currently too long, it is chopped off at the limit. Any marked text will
632/// be unmarked. The cursor position is set to 0 and the first part of the
633/// string is shown.
634/// See also GetMaxLength().
635
637{
638 fMaxLen = maxlen < 0 ? 0 : maxlen; // safety check for maxlen < 0
639
640 Int_t dif = fText->GetTextLength() - fMaxLen;
641 if (dif > 0) fText->RemoveText(fMaxLen, dif); // truncate
642
644 Deselect();
645
646 // ChangedBy("SetMaxLength"); // emit signal ChangedBy
647}
648
649////////////////////////////////////////////////////////////////////////////////
650/// The echo modes available are:
651///
652/// <ul>
653/// <li> kNormal - display characters as they are entered. This is the default.
654/// <li> kNoEcho - do not display anything.
655/// <li> kPassword - display asterisks instead of the characters actually entered.
656/// </ul>
657///
658/// It is always possible to cut and paste any marked text; only the widget's own
659/// display is affected.
660/// See also GetEchoMode(), GetDisplayText().
661
663{
664 if (fEchoMode == mode) return;
665
666 Int_t offset = IsFrameDrawn() ? 4 : 0;
667 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
668 offset = 2;
669 fEchoMode = mode;
670 if (GetEchoMode() == kNoEcho) { fCursorX = offset; }
671 UpdateOffset();
672 fClient->NeedRedraw(this);
673 // ChangedBy("SetEchoMode"); // emit signal ChangedBy
674}
675
676////////////////////////////////////////////////////////////////////////////////
677/// Returns the text marked by the user (e.g. by clicking and
678/// dragging), or zero if no text is marked.
679/// See also HasMarkedText().
680
682{
683 Int_t minP = MinMark();
684 Int_t len = MaxMark() - minP;
685 TString res(GetText()+minP,len);
686 return res;
687}
688
689////////////////////////////////////////////////////////////////////////////////
690/// New character mark at position pos.
691/// See also SetCursorPosition().
692
694{
695 TString dt = GetDisplayText();
696 Int_t offset = IsFrameDrawn() ? 4 : 0;
697 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
698 offset = 2;
699 Int_t x = fOffset + offset;
700 Int_t len = dt.Length();
701
702 Int_t pos = newPos < len ? newPos : len;
703 fEndIX = pos < 0 ? 0 : pos;
704
707
708 if (fSelectionOn) {
709 fEndX = x + gVirtualX->TextWidth(fFontStruct, dt.Data() , fEndIX);
710 fStartX = x + gVirtualX->TextWidth(fFontStruct, dt.Data() , fStartIX);
711 }
712}
713
714////////////////////////////////////////////////////////////////////////////////
715/// Set the cursor position to newPos.
716/// See also NewMark().
717
719{
720 Int_t offset = IsFrameDrawn() ? 4 : 0;
721 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
722 offset = 2;
723 if (GetEchoMode() == kNoEcho) { fCursorX = offset; return; }
724
725 UpdateOffset();
726 TString dt = GetDisplayText();
727
728 Int_t x = fOffset + offset;
729 Int_t len = dt.Length();
730
731 Int_t pos;
732
733 if (newPos < len)
734 pos = newPos;
735 else {
736 pos = len;
737 if (newPos > len) CursorOutRight();
738 }
739
740 if (pos < 0) {
741 fCursorIX = 0;
743 } else
744 fCursorIX = pos;
745
746 fCursorX = x + gVirtualX->TextWidth(fFontStruct, dt.Data(), fCursorIX);
747
748 if (!fSelectionOn){
751 }
752}
753
754////////////////////////////////////////////////////////////////////////////////
755/// Marks the word nearest to cursor position.
756/// See also HandleDoubleClick().
757
759{
760 Int_t i = pos - 1;
761 while (i >= 0 && isprint(GetText()[i]) && !isspace(GetText()[i])) i--;
762 i++;
763 Int_t newStartIX = i;
764
765 i = pos;
766 while (isprint(GetText()[i]) && !isspace(GetText()[i])) i++;
767 while(isspace(GetText()[i])) i++;
768
770 fStartIX = newStartIX;
771 fEndIX = i;
772 NewMark(i);
773}
774
775////////////////////////////////////////////////////////////////////////////////
776/// Removes any currently selected text, inserts newText,
777/// sets it as the new contents of the text entry.
778
779void TGTextEntry::Insert(const char *newText)
780{
781 TString old(GetText());
782 TString t(newText);
783
784 if (t.IsNull()) return;
785
786 for (int i=0; i<t.Length(); i++) {
787 if (t[i] < ' ') t[i] = ' '; // unprintable/linefeed becomes space
788 }
789
790 Int_t minP = MinMark();
791 Int_t maxP = MaxMark();
792 Int_t cp = fCursorIX;
793
794 if (HasMarkedText()) {
795 fText->RemoveText(minP, maxP-minP);
796 cp = minP;
797 }
798
799 if (fInsertMode == kReplace) fText->RemoveText(cp,t.Length());
800 Int_t ncp = TMath::Min(cp+t.Length(), GetMaxLength());
801 fText->AddText(cp, t.Data());
803 if (dlen>0) fText->RemoveText(GetMaxLength(),dlen); // truncate
804
806 if (old != GetText()) TextChanged();
807}
808
809////////////////////////////////////////////////////////////////////////////////
810/// Moves the cursor rightwards one or more characters.
811/// See also CursorLeft().
812
814{
815 Int_t cp = fCursorIX + steps;
816
817 if (cp == fCursorIX) {
818 if (!mark) {
821 }
822 } else if (mark) {
824 NewMark(cp);
825 } else {
828 }
829}
830
831////////////////////////////////////////////////////////////////////////////////
832/// Moves the cursor leftwards one or more characters.
833/// See also CursorRight().
834
836{
837 CursorRight(mark, -steps);
838}
839
840////////////////////////////////////////////////////////////////////////////////
841/// Moves the cursor one word to the right. If mark is kTRUE, the text
842/// is marked.
843/// See also CursorWordBackward().
844
846{
847 Int_t i = fCursorIX;
848 while (i < (Int_t)fText->GetTextLength() && !isspace(GetText()[i])) ++i;
849 while (i < (Int_t)fText->GetTextLength() && isspace(GetText()[i])) ++i;
850 CursorRight(mark, i - fCursorIX);
851}
852
853////////////////////////////////////////////////////////////////////////////////
854/// Moves the cursor one word to the left. If mark is kTRUE, the text
855/// is marked.
856/// See also CursorWordForward().
857
859{
860 Int_t i = fCursorIX;
861 while (i > 0 && isspace(GetText()[i-1])) --i;
862 while (i > 0 && !isspace(GetText()[i-1])) --i;
863 CursorLeft(mark, fCursorIX - i);
864}
865
866////////////////////////////////////////////////////////////////////////////////
867/// Deletes the character on the left side of the text cursor and moves the
868/// cursor one position to the left. If a text has been marked by the user
869/// (e.g. by clicking and dragging) the cursor will be put at the beginning
870/// of the marked text and the marked text will be removed.
871/// See also Del().
872
874{
875 if (HasMarkedText()) {
876 Del();
877 } else if (fCursorIX > 0) {
879 Del();
880 }
881}
882
883////////////////////////////////////////////////////////////////////////////////
884/// Deletes the character on the right side of the text cursor. If a text
885/// has been marked by the user (e.g. by clicking and dragging) the cursor
886/// will be put at the beginning of the marked text and the marked text will
887/// be removed.
888/// See also Backspace().
889
891{
892 Int_t minP = MinMark();
893 Int_t maxP = MaxMark();
894 Int_t offset = IsFrameDrawn() ? 4 : 0;
895 Int_t w = GetWidth() - 2 * offset; // subtract border twice
896
897 if (HasMarkedText()) {
898 fText->RemoveText(minP, maxP-minP);
900 TString dt = GetDisplayText();
901 Int_t textWidth = gVirtualX->TextWidth(fFontStruct, dt.Data(), dt.Length());
902 fOffset = w - textWidth - 1;
903 SetCursorPosition(minP);
904 } else if (fCursorIX != (Int_t)fText->GetTextLength()) {
907 TString dt = GetDisplayText();
908 Int_t textWidth = gVirtualX->TextWidth(fFontStruct, dt.Data(), dt.Length());
909 fOffset = w - textWidth - 1;
911 }
912 TextChanged();
913}
914
915////////////////////////////////////////////////////////////////////////////////
916/// Deletes all characters on the right side of the cursor.
917/// See also Del() Backspace().
918
920{
924 TextChanged(); // emit signal
925 }
926}
927
928////////////////////////////////////////////////////////////////////////////////
929/// Copies the marked text to the clipboard, if there is any and
930/// GetEchoMode() is kNormal.
931/// See also Cut() Paste().
932
934{
935 if (HasMarkedText() && GetEchoMode() == kNormal) {
937 *fgClipboardText = GetMarkedText(); // assign
938 gVirtualX->SetPrimarySelectionOwner(fId);
939 }
940}
941
942////////////////////////////////////////////////////////////////////////////////
943/// Inserts text at the cursor position, deleting any
944/// previous marked text.
945/// See also CopyText() Cut().
946
948{
949 if (gVirtualX->GetPrimarySelectionOwner() == kNone) {
950 // No primary selection, so use the buffer
952 } else {
953 gVirtualX->ConvertPrimarySelection(fId, fClipboard, 0);
954 }
955}
956
957////////////////////////////////////////////////////////////////////////////////
958/// Copies the marked text to the clipboard and deletes it, if there is any.
959/// See also CopyText() Paste().
960
962{
963 if (HasMarkedText()) {
964 CopyText();
965 Del();
966 }
967}
968
969////////////////////////////////////////////////////////////////////////////////
970/// Clears up the text entry.
971
973{
974 SetText("");
975}
976
977////////////////////////////////////////////////////////////////////////////////
978/// Moves the text cursor to the left end of the line. If mark is kTRUE text
979/// will be marked towards the first position, if not any marked text will
980/// be unmarked if the cursor is moved.
981/// See also End().
982
984{
985 fOffset = 0;
986 if (mark){
989 UpdateOffset();
990 NewMark(0);
991 } else {
994 }
995}
996
997////////////////////////////////////////////////////////////////////////////////
998/// Moves the text cursor to the right end of the line. If mark is kTRUE text
999/// will be marked towards the last position, if not any marked text will
1000/// be unmarked if the cursor is moved.
1001/// See also Home().
1002
1004{
1005 TString dt = GetDisplayText();
1006 Int_t len = dt.Length();
1007
1008 fOffset = (Int_t)GetWidth() - gVirtualX->TextWidth(fFontStruct, dt.Data(), len);
1009 if (fOffset > 0) fOffset = 0;
1010
1011 if (mark){
1014 UpdateOffset();
1015 NewMark(len);
1016 } else {
1019 }
1020}
1021
1022////////////////////////////////////////////////////////////////////////////////
1023/// Selects all text (i.e. marks it) and moves the cursor to the
1024/// end. Useful when a default value has been inserted. If the user
1025/// types before clicking on the widget the selected text will be
1026/// erased.
1027
1029{
1031 fStartIX = 0;
1033 DoRedraw();
1034}
1035
1036////////////////////////////////////////////////////////////////////////////////
1037/// Deselects all text (i.e. removes marking) and leaves the cursor at the
1038/// current position.
1039
1041{
1044 DoRedraw();
1045}
1046
1047////////////////////////////////////////////////////////////////////////////////
1048/// Draw the border of the text entry widget.
1049
1051{
1054 if (gClient->GetStyle() < 2) {
1055 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, fWidth-2, 0);
1056 gVirtualX->DrawLine(fId, GetShadowGC()(), 0, 0, 0, fHeight-2);
1057 gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, fWidth-3, 1);
1058 gVirtualX->DrawLine(fId, GetBlackGC()(), 1, 1, 1, fHeight-3);
1059
1060 gVirtualX->DrawLine(fId, GetHilightGC()(), 0, fHeight-1, fWidth-1, fHeight-1);
1061 gVirtualX->DrawLine(fId, GetHilightGC()(), fWidth-1, fHeight-1, fWidth-1, 0);
1062 gVirtualX->DrawLine(fId, GetBckgndGC()(), 1, fHeight-2, fWidth-2, fHeight-2);
1063 gVirtualX->DrawLine(fId, GetBckgndGC()(), fWidth-2, 1, fWidth-2, fHeight-2);
1064 break;
1065 }
1066 default:
1068 break;
1069 }
1070}
1071
1072////////////////////////////////////////////////////////////////////////////////
1073/// Draw the text entry widget.
1074
1076{
1077 Int_t x, y, max_ascent, max_descent, h;
1078 Int_t offset = IsFrameDrawn() ? 4 : 0;
1079 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
1080 offset = 2;
1081 TString dt = GetDisplayText(); // text to be displayed
1082 Int_t len = dt.Length(); // length of displayed text
1083
1084 // TGFrame::DoRedraw() == drawing border twice
1085 Int_t border = IsFrameDrawn() ? fBorderWidth : 0;
1086
1087 gVirtualX->ClearArea(fId, border, border,
1088 fWidth - (border << 1), fHeight - (border << 1));
1089
1090 gVirtualX->GetFontProperties(fFontStruct, max_ascent, max_descent);
1091
1092 h = max_ascent + max_descent;
1093 y = (fHeight - h) >> 1 ;
1094 x = fOffset + offset;
1095
1096 if (fEchoMode == kNoEcho) {
1098 fCursorX = offset;
1099 }
1100
1101 if ((GetInsertMode() == kInsert) || (fEchoMode == kNoEcho)) {
1102 // line cursor
1103 if (fCursorOn) {
1104 gVirtualX->DrawLine(fId, GetBlackGC()(), fCursorX, y - 1,
1105 fCursorX, h + 2);
1106 }
1107 gVirtualX->DrawString(fId, fNormGC(), x, y + max_ascent, dt.Data(), len);
1108
1109 } else {
1110 // filled rectangle (block) cursor
1111 gVirtualX->DrawString(fId, fNormGC(), x, y + max_ascent, dt.Data(), len);
1112
1113 if (fCursorOn) {
1114 Int_t ind = fCursorIX < len-1 ? fCursorIX : len - 1;
1115 Int_t charWidth = ind < 0 || fCursorIX > len - 1 ? 4 :
1116 gVirtualX->TextWidth(fFontStruct, &dt[ind],1);
1117
1118 Int_t before = gVirtualX->TextWidth(fFontStruct, dt, fCursorIX) + x;
1119
1120 gVirtualX->FillRectangle(fId, fSelbackGC , before, y ,
1121 charWidth , h + 1);
1122
1123 if (fCursorIX < len)
1124 gVirtualX->DrawString(fId, fSelGC(), before, y + max_ascent, &dt[ind], 1);
1125 }
1126 }
1127
1128 if (fSelectionOn) {
1129 int xs, ws, ixs, iws;
1130
1131 xs = TMath::Min(fStartX, fEndX);
1132 ws = TMath::Abs(fEndX - fStartX);
1133 ixs = TMath::Min(fStartIX, fEndIX);
1134 iws = TMath::Abs(fEndIX - fStartIX);
1135
1136 gVirtualX->FillRectangle(fId, fSelbackGC, xs, y, ws, h + 1);
1137
1138 gVirtualX->DrawString(fId, fSelGC(), xs, y + max_ascent,
1139 dt.Data() + ixs, iws);
1140 }
1141 if (IsFrameDrawn()) DrawBorder();
1142}
1143
1144////////////////////////////////////////////////////////////////////////////////
1145/// The key press event handler converts a key press to some line editor
1146/// action. Here are the default key bindings:
1147///
1148/// <ul>
1149/// <li><i> Left Arrow </i>
1150/// Move the cursor one character leftwards.
1151/// Scroll the text when cursor is out of frame.
1152/// <li><i> Right Arrow </i>
1153/// Move the cursor one character rightwards
1154/// Scroll the text when cursor is out of frame.
1155/// <li><i> Backspace </i>
1156/// Deletes the character on the left side of the text cursor and moves the
1157/// cursor one position to the left. If a text has been marked by the user
1158/// (e.g. by clicking and dragging) the cursor will be put at the beginning
1159/// of the marked text and the marked text will be removed.
1160/// <li><i> Home </i>
1161/// Moves the text cursor to the left end of the line. If mark is TRUE text
1162/// will be marked towards the first position, if not any marked text will
1163/// be unmarked if the cursor is moved.
1164/// <li><i> End </i>
1165/// Moves the text cursor to the right end of the line. If mark is TRUE text
1166/// will be marked towards the last position, if not any marked text will
1167/// be unmarked if the cursor is moved.
1168/// <li><i> Delete </i>
1169/// Deletes the character on the right side of the text cursor. If a text
1170/// has been marked by the user (e.g. by clicking and dragging) the cursor
1171/// will be put at the beginning of the marked text and the marked text will
1172/// be removed.
1173/// <li><i> Insert </i>
1174/// Switches character insert mode.
1175/// <li><i> Shift - Left Arrow </i>
1176/// Mark text one character leftwards
1177/// <li><i> Shift - Right Arrow </i>
1178/// Mark text one character rightwards
1179/// <li><i> Control - Left Arrow </i>
1180/// Move the cursor one word leftwards
1181/// <li><i> Control - Right Arrow </i>
1182/// Move the cursor one word rightwards.
1183/// <li><i> Control - Shift - Left Arrow </i>
1184/// Mark text one word leftwards
1185/// <li><i> Control - Shift - Right Arrow </i>
1186/// Mark text one word rightwards
1187/// <li><i> Control-A </i>
1188/// Move the cursor to the beginning of the line
1189/// <li><i> Control-B </i>
1190/// Move the cursor one character leftwards
1191/// <li><i> Control-C </i>
1192/// Copy the marked text to the clipboard.
1193/// <li><i> Control-D </i>
1194/// Delete the character to the right of the cursor
1195/// <li><i> Control-E </i>
1196/// Move the cursor to the end of the line
1197/// <li><i> Control-F </i>
1198/// Move the cursor one character rightwards
1199/// <li><i> Control-H </i>
1200/// Delete the character to the left of the cursor
1201/// <li><i> Control-K </i>
1202/// Delete marked text if any or delete all
1203/// characters to the right of the cursor
1204/// <li><i> Control-U </i>
1205/// Delete all characters on the line
1206/// <li><i> Control-V </i>
1207/// Paste the clipboard text into line edit.
1208/// <li><i> Control-X </i>
1209/// Cut the marked text, copy to clipboard.
1210/// <li><i> Control-Y </i>
1211/// Paste the clipboard text into line edit.
1212/// </ul>
1213///
1214/// All other keys with valid ASCII codes insert themselves into the line.
1215
1217{
1218 Int_t n;
1219 char tmp[10];
1220 UInt_t keysym;
1221
1222 if (fTip && event->fType == kGKeyPress) fTip->Hide();
1223
1224 if (!IsEnabled() || event->fType != kGKeyPress) return kTRUE;
1225
1226 gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
1227 n = strlen(tmp);
1228
1229 if ((EKeySym)keysym == kKey_Enter || (EKeySym)keysym == kKey_Return) {
1230
1231 ReturnPressed(); // emit signal
1232 if (ROOT::Detail::HasBeenDeleted(this)) return kTRUE;
1234
1235 } else if (event->fState & kKeyShiftMask && (EKeySym)keysym == kKey_Backtab) {
1236 ShiftTabPressed(); // emit signal
1238 return kTRUE;
1239
1240 } else if ((EKeySym)keysym == kKey_Tab) {
1241
1242 TabPressed(); // emit signal
1244
1245 } else if (event->fState & kKeyControlMask) { // Cntrl key modifier pressed
1246 switch ((EKeySym)keysym & ~0x20) { // treat upper and lower the same
1247 case kKey_A:
1248 Home(event->fState & kKeyShiftMask);
1249 break;
1250 case kKey_B:
1252 break;
1253 case kKey_C:
1254 CopyText();
1255 break;
1256 case kKey_D:
1257 Del();
1258 break;
1259 case kKey_E:
1260 End(event->fState & kKeyShiftMask);
1261 break;
1262 case kKey_F:
1264 break;
1265 case kKey_H:
1266 Backspace();
1267 break;
1268 case kKey_K:
1269 HasMarkedText() ? Del() : Remove();
1270 break;
1271 case kKey_U:
1272 Home();
1273 Remove();
1274 break;
1275 case kKey_V:
1276 Paste();
1277 break;
1278 case kKey_X:
1279 Cut();
1280 break;
1281 case kKey_Y:
1282 Paste();
1283 break;
1284 case kKey_Right:
1286 break;
1287 case kKey_Left:
1289 break;
1290 }
1291 } else if (n && keysym <127 && keysym >=32 && // printable keys
1292 (EKeySym)keysym != kKey_Delete &&
1293 (EKeySym)keysym != kKey_Backspace) {
1294
1295 Insert(tmp);
1297
1298 } else {
1299 switch ((EKeySym)keysym) {
1300 case kKey_Down:
1301 CursorOutDown();
1302 break;
1303 case kKey_Up:
1304 CursorOutUp();
1305 break;
1306 case kKey_Left:
1308 break;
1309 case kKey_Right:
1311 break;
1312 case kKey_Backspace:
1313 Backspace();
1314 break;
1315 case kKey_Home:
1316 Home(event->fState & kKeyShiftMask);
1317 break;
1318 case kKey_End:
1319 End(event->fState & kKeyShiftMask);
1320 break;
1321 case kKey_Delete:
1322 Del();
1323 break;
1324 case kKey_Insert: // switch on/off insert mode
1326 break;
1327 default:
1328 // empty case to avoid compiler warning about unhandled enum values
1329 break;
1330 }
1331 }
1332
1333 UpdateOffset();
1334 fClient->NeedRedraw(this);
1335
1336 return kTRUE;
1337}
1338
1339////////////////////////////////////////////////////////////////////////////////
1340/// Handle mouse button event in text entry widget.
1341
1343{
1344 if (fTip) fTip->Hide();
1345
1346 if (!IsEnabled()) return kTRUE;
1347
1348 if (event->fType == kButtonPress) {
1349 SetFocus();
1350 if (fEchoMode == kNoEcho) return kTRUE;
1351
1352 if (event->fCode == kButton1) {
1353 Int_t offset = IsFrameDrawn() ? 4 : 0;
1354 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
1355 offset = 2;
1356 Int_t x = fOffset + offset;
1357 Int_t position = GetCharacterIndex(event->fX - x);
1359 SetCursorPosition(position);
1360 DoRedraw();
1361 } else if (event->fCode == kButton2) {
1362 if (gVirtualX->GetPrimarySelectionOwner() == kNone) {
1363 // No primary selection, so use the cut buffer
1365 } else {
1366 gVirtualX->ConvertPrimarySelection(fId, fClipboard, event->fTime);
1367 }
1368 }
1369 }
1370 if (event->fType == kButtonRelease)
1371 if (event->fCode == kButton1)
1372 CopyText();
1373
1374 return kTRUE;
1375}
1376
1377////////////////////////////////////////////////////////////////////////////////
1378/// Handle mouse crossing event.
1379
1381{
1382 if (event->fType == kEnterNotify) {
1383 if (fTip) fTip->Reset();
1384 } else {
1385 if (fTip) fTip->Hide();
1386 }
1387
1388 return kTRUE;
1389}
1390
1391////////////////////////////////////////////////////////////////////////////////
1392/// Handle mouse motion event in the text entry widget.
1393
1395{
1396 if (!IsEnabled() || (GetEchoMode() == kNoEcho)) return kTRUE;
1397
1398 Int_t offset = IsFrameDrawn() ? 4 : 0;
1399 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
1400 offset = 2;
1401 Int_t x = fOffset + offset;
1402 Int_t position = GetCharacterIndex(event->fX - x); // + 1;
1404 NewMark(position);
1405 UpdateOffset();
1406 DoRedraw();
1407 return kTRUE;
1408}
1409
1410////////////////////////////////////////////////////////////////////////////////
1411/// Handle mouse double click event in the text entry widget.
1412
1414{
1415 if (!IsEnabled()) return kTRUE;
1416
1417 Int_t offset = IsFrameDrawn() ? 4 : 0;
1418 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
1419 offset = 2;
1420 Int_t x = fOffset + offset ;
1421
1422 DoubleClicked();
1423 SetFocus();
1424 if (fEchoMode == kNoEcho) return kTRUE;
1425
1426 Int_t position = GetCharacterIndex(event->fX - x);
1427 MarkWord(position);
1428 return kTRUE;
1429}
1430
1431////////////////////////////////////////////////////////////////////////////////
1432/// Handles resize events for this widget.
1433
1435{
1437 Bool_t wasSelection = fSelectionOn;
1438 Int_t end = fEndIX, start = fStartIX;
1440 UpdateOffset();
1442 fSelectionOn = wasSelection;
1443 fEndIX = end;
1444 fStartIX = start;
1446 return kTRUE;
1447}
1448
1449////////////////////////////////////////////////////////////////////////////////
1450/// Handle focus change event in text entry widget.
1451
1453{
1454 if (!IsEnabled()) return kTRUE;
1455
1456 // check this when porting to Win32
1457 if (event->fType == kFocusIn) {
1458 fCursorOn = kTRUE;
1459 if (!fCurBlink) fCurBlink = new TBlinkTimer(this, 500);
1460 fCurBlink->Reset();
1461 gBlinkingEntry = this;
1463 } else {
1464 fCursorOn = kFALSE;
1465 // fSelectionOn = kFALSE; // "web browser location behavior"
1466 if (fCurBlink) fCurBlink->Remove();
1467 gBlinkingEntry = 0;
1468 }
1469 fClient->NeedRedraw(this);
1470 return kTRUE;
1471}
1472
1473////////////////////////////////////////////////////////////////////////////////
1474/// Handle text selection event.
1475
1477{
1478 PastePrimary((Window_t)event->fUser[0], (Atom_t)event->fUser[3], kTRUE);
1479 return kTRUE;
1480}
1481
1482////////////////////////////////////////////////////////////////////////////////
1483/// Handle selection clear event.
1484
1486{
1489 fClient->NeedRedraw(this);
1490 return kTRUE;
1491}
1492
1493////////////////////////////////////////////////////////////////////////////////
1494/// Handle request to send current clipboard contents to requestor window.
1495
1497{
1498 Event_t reply;
1499 char *buffer;
1500 Long_t len;
1501 Atom_t targets[2];
1502 Atom_t type;
1503
1504 reply.fType = kSelectionNotify;
1505 reply.fTime = event->fTime;
1506 reply.fUser[0] = event->fUser[0]; // requestor
1507 reply.fUser[1] = event->fUser[1]; // selection
1508 reply.fUser[2] = event->fUser[2]; // target
1509 reply.fUser[3] = event->fUser[3]; // property
1510
1511 targets[0] = gVirtualX->InternAtom("TARGETS", kFALSE);
1512 targets[1] = gVirtualX->InternAtom("XA_STRING", kFALSE);
1513
1514 if ((Atom_t)event->fUser[2] == targets[0]) {
1515 type = gVirtualX->InternAtom("XA_ATOM", kFALSE);
1516 gVirtualX->ChangeProperty((Window_t) event->fUser[0], (Atom_t) event->fUser[3],
1517 type, (UChar_t*) targets, (Int_t) 2);
1518
1519 gVirtualX->SendEvent((Window_t)event->fUser[0], &reply);
1520 return kTRUE;
1521 }
1522
1523 len = 0;
1525 buffer = new char[len+1];
1526 if (fgClipboardText) strlcpy (buffer, fgClipboardText->Data(), len+1);
1527
1528 gVirtualX->ChangeProperty((Window_t) event->fUser[0], (Atom_t) event->fUser[3],
1529 (Atom_t) event->fUser[2], (UChar_t*) buffer,
1530 (Int_t) len);
1531 delete [] buffer;
1532
1533 gVirtualX->SendEvent((Window_t)event->fUser[0], &reply);
1534
1535 return kTRUE;
1536}
1537
1538////////////////////////////////////////////////////////////////////////////////
1539/// Paste text from selection (either primary or cut buffer) into
1540/// text entry widget.
1541
1543{
1544 TString data;
1545 Int_t nchar;
1546
1547 if (!IsEnabled()) return;
1548
1549 gVirtualX->GetPasteBuffer(wid, property, data, nchar, del);
1550
1551 if (nchar) Insert(data.Data());
1552 fClient->NeedRedraw(this);
1553}
1554
1555////////////////////////////////////////////////////////////////////////////////
1556/// Handle cursor blink timer.
1557
1559{
1561 DoRedraw();
1562 return kTRUE;
1563}
1564
1565////////////////////////////////////////////////////////////////////////////////
1566/// Returns kTRUE if cursor is out of frame.
1567
1569{
1570 // fCursorX = fOffset + 4 + gVirtualX->TextWidth(fFontStruct,
1571 // GetDisplayText(), fCursorIX);
1572
1573 Int_t offset = IsFrameDrawn() ? 4 : 0;
1574 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
1575 offset = 2;
1576 Int_t w = GetWidth();
1577 return ((fCursorX < offset) || (fCursorX > w-offset));
1578}
1579
1580////////////////////////////////////////////////////////////////////////////////
1581/// Shift position of cursor by one character.
1582
1584{
1585 if (GetEchoMode() == kNoEcho) return;
1586
1587 TString dt = GetDisplayText();
1588 Int_t len = dt.Length();
1589 Int_t ind = fCursorIX < len-1 ? fCursorIX : len-1;
1590 Int_t charWidth = ind < 0 ? 4 : gVirtualX->TextWidth(fFontStruct, &dt[ind],1);
1591 Int_t w = GetWidth();
1592 Int_t d;
1593 Int_t offset = IsFrameDrawn() ? 4 : 0;
1594 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
1595 offset = 2;
1596
1597 if (fCursorX < offset) {
1598 fOffset += charWidth;
1599 fCursorX += charWidth;
1600 d = fCursorX;
1601
1602 if (d < offset){ // correction
1603 d -= offset;
1604 fOffset -= d;
1605 fCursorX -= d;
1606 }
1607 } else if (fCursorX > w-offset) {
1608 fOffset -= charWidth;
1609 fCursorX -= charWidth;
1610 d = w - fCursorX;
1611
1612 if (d < offset) { // correction
1613 d -= offset;
1614 fOffset += d;
1615 fCursorX += d;
1616 }
1617 }
1618}
1619
1620////////////////////////////////////////////////////////////////////////////////
1621/// Updates start text offset according GetAlignment() mode,
1622/// if cursor is out of frame => scroll the text.
1623/// See also SetAlignment() and ScrollByChar().
1624
1626{
1627 TString dt = GetDisplayText();
1628 Int_t textWidth = gVirtualX->TextWidth(fFontStruct, dt.Data() , dt.Length());
1629 Int_t offset = IsFrameDrawn() ? 4 : 0;
1630 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
1631 offset = 2;
1632 Int_t w = GetWidth() - 2 * offset; // subtract border twice
1633
1634 if (fAlignment == kTextRight) fOffset = w - textWidth - 1;
1635 else if (fAlignment == kTextCenterX) fOffset = (w - textWidth)/2;
1636 else if (fAlignment == kTextLeft) fOffset = 0;
1637 if (textWidth > 0 && textWidth > w) { // may need to scroll.
1639 }
1640}
1641
1642////////////////////////////////////////////////////////////////////////////////
1643/// Set tool tip text associated with this text entry. The delay is in
1644/// milliseconds (minimum 250). To remove tool tip call method with
1645/// text = 0.
1646
1647void TGTextEntry::SetToolTipText(const char *text, Long_t delayms)
1648{
1649 if (fTip) {
1650 delete fTip;
1651 fTip = 0;
1652 }
1653
1654 if (text && strlen(text))
1655 fTip = new TGToolTip(fClient->GetDefaultRoot(), this, text, delayms);
1656}
1657
1658////////////////////////////////////////////////////////////////////////////////
1659/// Set focus to this text entry.
1660
1662{
1663 if (gBlinkingEntry && (gBlinkingEntry != this)) {
1665 }
1666 RequestFocus();
1667}
1668
1669////////////////////////////////////////////////////////////////////////////////
1670/// Inserts text at position pos, clears the selection and moves
1671/// the cursor to the end of the line.
1672/// If necessary the text is truncated to fit MaxLength().
1673/// See also GetText(), SetText(), AppendText(), RemoveText().
1674
1675void TGTextEntry::InsertText(const char *text, Int_t pos)
1676{
1677 Int_t position = TMath::Min((Int_t)fText->GetTextLength(), pos);
1678 TString newText(GetText());
1679 newText.Insert(position, text);
1680 SetText(newText.Data());
1681}
1682
1683////////////////////////////////////////////////////////////////////////////////
1684/// Appends text to the end of text entry, clears the selection
1685/// and moves the cursor to the end of the line.
1686/// If necessary the text is truncated to fit MaxLength().
1687/// See also GetText(), InsertText(), SetText(), RemoveText().
1688
1690{
1692}
1693
1694////////////////////////////////////////////////////////////////////////////////
1695/// Removes text at the range, clears the selection and moves
1696/// the cursor to the end of the line.
1697/// See also GetText(), InsertText(), SetText(), AppendText().
1698
1700{
1701 Int_t pos = TMath::Min(start, end);
1702 Int_t len = TMath::Abs(end-start);
1703 TString newText(GetText());
1704 newText.Remove(pos, len);
1705 SetText(newText.Data());
1706}
1707
1708
1709////////////////////////////////////////////////////////////////////////////////
1710/// Changes text font.
1711/// If local is kTRUE font is changed locally.
1712
1714{
1715 if (font == fFontStruct) return;
1716
1717 FontH_t v = gVirtualX->GetFontHandle(font);
1718
1719 if (!v) return;
1720
1721 if (local) {
1722 TGGC *gc = new TGGC(fNormGC); // copy
1724 fNormGC = *gc;
1725 gc = new TGGC(fSelGC); // copy
1726 fSelGC = *gc;
1727 }
1728 fNormGC.SetFont(v);
1729 fSelGC.SetFont(v);
1730 fFontStruct = font;
1731 fClient->NeedRedraw(this);
1732}
1733
1734////////////////////////////////////////////////////////////////////////////////
1735/// Changes text font specified by name.
1736/// If local is kTRUE font is changed locally.
1737
1738void TGTextEntry::SetFont(const char *fontName, Bool_t local)
1739{
1740 TGFont *font = fClient->GetFont(fontName);
1741 if (font) {
1742 SetFont(font->GetFontStruct(), local);
1743 }
1744}
1745
1746////////////////////////////////////////////////////////////////////////////////
1747/// Changes text font specified by pointer to TGFont object.
1748/// If local is kTRUE font is changed locally.
1749
1751{
1752 if (font) {
1753 SetFont(font->GetFontStruct(), local);
1754 }
1755}
1756
1757////////////////////////////////////////////////////////////////////////////////
1758/// Changes text color.
1759/// If local is true color is changed locally.
1760
1762{
1763 if (local) {
1764 TGGC *gc = new TGGC(fNormGC); // copy
1766 fNormGC = *gc;
1767 }
1768
1769 fNormGC.SetForeground(color);
1770 fClient->NeedRedraw(this);
1771}
1772
1773////////////////////////////////////////////////////////////////////////////////
1774/// Changes text color.
1775/// If local is true color is changed locally.
1776
1778{
1779 if (color) {
1780 SetTextColor(color->GetPixel(), local);
1781 }
1782}
1783
1784////////////////////////////////////////////////////////////////////////////////
1785/// Return default font structure in use.
1786
1788{
1789 if (!fgDefaultFont)
1790 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
1791 return fgDefaultFont->GetFontStruct();
1792}
1793
1794////////////////////////////////////////////////////////////////////////////////
1795/// Return default graphics context.
1796
1798{
1799 if (!fgDefaultGC)
1800 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
1801 return *fgDefaultGC;
1802}
1803
1804////////////////////////////////////////////////////////////////////////////////
1805/// Return selection graphics context.
1806
1808{
1810 fgDefaultSelectedGC = gClient->GetResourcePool()->GetSelectedGC();
1811 return *fgDefaultSelectedGC;
1812}
1813
1814////////////////////////////////////////////////////////////////////////////////
1815/// Return graphics context for highlighted frame background.
1816
1818{
1820 fgDefaultSelectedBackgroundGC = gClient->GetResourcePool()->GetSelectedBckgndGC();
1822}
1823
1824////////////////////////////////////////////////////////////////////////////////
1825/// Save a text entry widget as a C++ statement(s) on output stream out.
1826
1827void TGTextEntry::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1828{
1829 char quote = '"';
1830
1831 // font + GC
1832 option = GetName()+5; // unique digit id of the name
1833 TString parGC, parFont;
1834 // coverity[returned_null]
1835 // coverity[dereference]
1836 parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
1837 // coverity[returned_null]
1838 // coverity[dereference]
1839 parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
1840
1841 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC.GetGC())) {
1842 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
1843 if (ufont) {
1844 ufont->SavePrimitive(out, option);
1845 parFont.Form("ufont->GetFontStruct()");
1846 }
1847
1848 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC.GetGC());
1849 if (userGC) {
1850 userGC->SavePrimitive(out, option);
1851 parGC.Form("uGC->GetGC()");
1852 }
1853 }
1854
1856
1857 out << " TGTextEntry *";
1858 out << GetName() << " = new TGTextEntry(" << fParent->GetName()
1859 << ", new TGTextBuffer(" << GetBuffer()->GetBufferLength() << ")";
1860
1861 if (fBackground == GetWhitePixel()) {
1862 if (GetOptions() == (kSunkenFrame | kDoubleBorder)) {
1864 if (fNormGC() == GetDefaultGC()()) {
1865 if (fWidgetId == -1) {
1866 out <<");" << std::endl;
1867 } else {
1868 out << "," << fWidgetId << ");" << std::endl;
1869 }
1870 } else {
1871 out << "," << fWidgetId << "," << parGC.Data() << ");" << std::endl;
1872 }
1873 } else {
1874 out << "," << fWidgetId << "," << parGC.Data() << "," << parFont.Data()
1875 <<");" << std::endl;
1876 }
1877 } else {
1878 out << "," << fWidgetId << "," << parGC.Data() << "," << parFont.Data()
1879 << "," << GetOptionString() << ");" << std::endl;
1880 }
1881 } else {
1882 out << "," << fWidgetId << "," << parGC.Data() << "," << parFont.Data()
1883 << "," << GetOptionString() << ",ucolor);" << std::endl;
1884 }
1885 if (option && strstr(option, "keep_names"))
1886 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
1887
1888 out << " " << GetName() << "->SetMaxLength(" << GetMaxLength() << ");" << std::endl;
1889
1890 out << " " << GetName() << "->SetAlignment(";
1891
1892 if (fAlignment == kTextLeft)
1893 out << "kTextLeft);" << std::endl;
1894
1895 if (fAlignment == kTextRight)
1896 out << "kTextRight);" << std::endl;
1897
1898 if (fAlignment == kTextCenterX)
1899 out << "kTextCenterX);" << std::endl;
1900
1901 out << " " << GetName() << "->SetText(" << quote << GetText() << quote
1902 << ");" << std::endl;
1903
1904 out << " " << GetName() << "->Resize("<< GetWidth() << "," << GetName()
1905 << "->GetDefaultHeight());" << std::endl;
1906
1907 if ((fDefWidth > 0) || (fDefHeight > 0)) {
1908 out << " " << GetName() << "->SetDefaultSize(";
1909 out << fDefWidth << "," << fDefHeight << ");" << std::endl;
1910 }
1911
1912 if (fTip) {
1913 TString tiptext = fTip->GetText()->GetString();
1914 tiptext.ReplaceAll("\n", "\\n");
1915 out << " ";
1916 out << GetName() << "->SetToolTipText(" << quote
1917 << tiptext << quote << ");" << std::endl;
1918 }
1919}
Handle_t Atom_t
WM token.
Definition GuiTypes.h:37
@ kGKeyPress
Definition GuiTypes.h:60
@ kButtonRelease
Definition GuiTypes.h:60
@ kSelectionNotify
Definition GuiTypes.h:63
@ kButtonPress
Definition GuiTypes.h:60
@ kFocusIn
Definition GuiTypes.h:61
@ kEnterNotify
Definition GuiTypes.h:61
const Mask_t kWABitGravity
Definition GuiTypes.h:144
const Mask_t kButtonMotionMask
Definition GuiTypes.h:164
const Mask_t kFocusChangeMask
Definition GuiTypes.h:169
const Mask_t kButtonPressMask
Definition GuiTypes.h:161
Handle_t FontH_t
Font handle (as opposed to Font_t which is an index)
Definition GuiTypes.h:35
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
const Mask_t kWAWinGravity
Definition GuiTypes.h:145
const Mask_t kAnyModifier
Definition GuiTypes.h:210
const Mask_t kKeyPressMask
Definition GuiTypes.h:159
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:38
const Mask_t kKeyShiftMask
Definition GuiTypes.h:195
@ kRaisedFrame
Definition GuiTypes.h:384
@ kSunkenFrame
Definition GuiTypes.h:383
@ kDoubleBorder
Definition GuiTypes.h:385
@ kFixedWidth
Definition GuiTypes.h:387
@ kFixedHeight
Definition GuiTypes.h:389
@ kOwnBackground
Definition GuiTypes.h:391
const Handle_t kNone
Definition GuiTypes.h:88
const Mask_t kKeyControlMask
Definition GuiTypes.h:197
const Mask_t kLeaveWindowMask
Definition GuiTypes.h:168
const Mask_t kStructureNotifyMask
Definition GuiTypes.h:166
const Mask_t kButtonReleaseMask
Definition GuiTypes.h:162
const Mask_t kEnterWindowMask
Definition GuiTypes.h:167
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
@ kButton2
Definition GuiTypes.h:214
@ kButton1
Definition GuiTypes.h:214
@ kAnyButton
Definition GuiTypes.h:214
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
const Atom_t kCutBuffer
in /usr/include/X11/Xatom.h
Definition GuiTypes.h:368
EKeySym
Definition KeySymbols.h:25
@ kKey_Right
Definition KeySymbols.h:42
@ kKey_Down
Definition KeySymbols.h:43
@ kKey_Y
Definition KeySymbols.h:150
@ kKey_B
Definition KeySymbols.h:127
@ kKey_F
Definition KeySymbols.h:131
@ kKey_Up
Definition KeySymbols.h:41
@ kKey_Return
Definition KeySymbols.h:30
@ kKey_C
Definition KeySymbols.h:128
@ kKey_Delete
Definition KeySymbols.h:33
@ kKey_A
Definition KeySymbols.h:126
@ kKey_Left
Definition KeySymbols.h:40
@ kKey_E
Definition KeySymbols.h:130
@ kKey_Backspace
Definition KeySymbols.h:29
@ kKey_D
Definition KeySymbols.h:129
@ kKey_X
Definition KeySymbols.h:149
@ kKey_Home
Definition KeySymbols.h:38
@ kKey_U
Definition KeySymbols.h:146
@ kKey_Insert
Definition KeySymbols.h:32
@ kKey_Enter
Definition KeySymbols.h:31
@ kKey_Tab
Definition KeySymbols.h:27
@ kKey_H
Definition KeySymbols.h:133
@ kKey_Backtab
Definition KeySymbols.h:28
@ kKey_End
Definition KeySymbols.h:39
@ kKey_K
Definition KeySymbols.h:136
@ kKey_V
Definition KeySymbols.h:147
#define d(i)
Definition RSha256.hxx:102
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
unsigned char UChar_t
Definition RtypesCore.h:38
long Long_t
Definition RtypesCore.h:54
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
#define gClient
Definition TGClient.h:156
TGTextEntry * gBlinkingEntry
ETextJustification
Definition TGWidget.h:22
@ kTextCenterX
Definition TGWidget.h:25
@ kTextLeft
Definition TGWidget.h:23
@ kTextRight
Definition TGWidget.h:24
@ kWidgetIsEnabled
Definition TGWidget.h:37
@ kWidgetWantFocus
Definition TGWidget.h:35
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 void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t del
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize wid
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 char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t nchar
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t property
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
Option_t Option_t TPoint TPoint const char text
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
#define gVirtualX
Definition TVirtualX.h:337
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
@ kTE_TEXTCHANGED
@ kTE_ENTER
@ kTE_TAB
@ kC_TEXTENTRY
TGTextEntry * fTextEntry
Bool_t Notify() override
Notify when timer times out and reset the timer.
TBlinkTimer(TGTextEntry *t, Long_t ms)
The color creation and management class.
Definition TColor.h:21
ULong_t GetPixel() const
Return pixel value corresponding to this color.
Definition TColor.cxx:1510
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition TGClient.cxx:234
void ProcessLine(TString cmd, Long_t msg, Long_t parm1, Long_t parm2)
Execute string "cmd" via the interpreter.
Definition TGClient.cxx:914
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get a font from the font pool.
Definition TGClient.cxx:348
const TGResourcePool * GetResourcePool() const
Definition TGClient.h:124
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:372
Encapsulate fonts used in the GUI system.
Definition TGFont.h:140
FontStruct_t GetFontStruct() const
Definition TGFont.h:184
void SavePrimitive(std::ostream &out, Option_t *="") override
Save the used font as a C++ statement(s) on output stream out.
Definition TGFont.cxx:1884
A subclasses of TGWindow, and is used as base class for some simple widgets (buttons,...
Definition TGFrame.h:80
void AddInput(UInt_t emask)
Add events specified in the emask to the events the frame should handle.
Definition TGFrame.cxx:339
static const TGGC & GetBlackGC()
Get black graphics context.
Definition TGFrame.cxx:735
UInt_t fOptions
frame options
Definition TGFrame.h:94
virtual Bool_t HandleConfigureNotify(Event_t *event)
This event is generated when the frame is resized.
Definition TGFrame.cxx:443
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition TGFrame.cxx:709
UInt_t fHeight
frame height
Definition TGFrame.h:88
virtual void DrawBorder()
Draw frame border.
Definition TGFrame.cxx:421
Int_t fBorderWidth
frame border width
Definition TGFrame.h:93
void SetBackgroundColor(Pixel_t back) override
Set background color (override from TGWindow base class).
Definition TGFrame.cxx:312
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition TGFrame.cxx:755
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:683
virtual UInt_t GetOptions() const
Definition TGFrame.h:197
TString GetOptionString() const
Returns a frame option string - used in SavePrimitive().
Definition TGFrame.cxx:2506
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
Definition TGFrame.cxx:645
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition TGFrame.cxx:765
UInt_t fWidth
frame width
Definition TGFrame.h:87
static Pixel_t fgWhitePixel
Definition TGFrame.h:103
UInt_t GetWidth() const
Definition TGFrame.h:224
void SaveUserColor(std::ostream &out, Option_t *)
Save a user color in a C++ macro file - used in SavePrimitive().
Definition TGFrame.cxx:2479
Pixel_t fBackground
frame background color
Definition TGFrame.h:95
static const TGGC & GetBckgndGC()
Get background color graphics context.
Definition TGFrame.cxx:775
TGGC * FindGC(const TGGC *gc)
Find graphics context. Returns 0 in case gc is not found.
Definition TGGC.cxx:951
Encapsulate a graphics context used in the low level graphics.
Definition TGGC.h:22
GContext_t GetGC() const
Definition TGGC.h:41
void SetFont(FontH_t v)
Set font.
Definition TGGC.cxx:411
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save graphics context info as a C++ statement(s) on output stream out.
Definition TGGC.cxx:627
void SetForeground(Pixel_t v)
Set foreground color.
Definition TGGC.cxx:278
TGClient * fClient
Connection to display server.
Definition TGObject.h:25
Handle_t GetId() const
Definition TGObject.h:41
Handle_t fId
X11/Win32 Window identifier.
Definition TGObject.h:24
Cursor_t GetTextCursor() const
Atom_t GetClipboard() const
TGGCPool * GetGCPool() const
const char * GetString() const
Definition TGString.h:30
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
UInt_t GetBufferLength() const
void AddText(Int_t pos, const char *text)
const char * GetString() const
void RemoveText(Int_t pos, Int_t length)
UInt_t GetTextLength() 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.
Int_t fOffset
start position of text (in pixels)
Definition TGTextEntry.h:37
virtual void SetFocus()
Set focus to this text entry.
void CursorLeft(Bool_t mark=kFALSE, Int_t steps=1)
Moves the cursor leftwards one or more characters.
Bool_t fFrameDrawn
kTRUE draw itself inside a two-pixel frame, kFALSE draw without any frame
Definition TGTextEntry.h:50
void CursorRight(Bool_t mark=kFALSE, Int_t steps=1)
Moves the cursor rightwards one or more characters.
Bool_t HasMarkedText() const
Int_t fStartIX
selection begin in characters
Definition TGTextEntry.h:34
virtual void SetEchoMode(EEchoMode mode=kNormal)
The echo modes available are:
virtual void SetDefaultSize(UInt_t w, UInt_t h)
Set the default / minimal size of the widget.
UInt_t fDefHeight
default height
Definition TGTextEntry.h:56
Bool_t HandleConfigureNotify(Event_t *event) override
Handles resize events for this widget.
virtual void SetMaxLength(Int_t maxlen)
Set the maximum length of the text in the editor.
EEchoMode fEchoMode
OPTION={GetMethod="GetEchoMode";SetMethod="SetEchoMode";Items=(kNormal="Normal",kNoEcho="No Echo",...
Definition TGTextEntry.h:51
static FontStruct_t GetDefaultFontStruct()
Return default font structure in use.
virtual void RemoveText(Int_t start, Int_t end)
Removes text at the range, clears the selection and moves the cursor to the end of the line.
Int_t fStartX
selection begin in pixels
Definition TGTextEntry.h:32
Bool_t HandleKey(Event_t *event) override
The key press event handler converts a key press to some line editor action.
TGTextBuffer * fText
text buffer
Definition TGTextEntry.h:31
Bool_t HandleSelectionRequest(Event_t *event) override
Handle request to send current clipboard contents to requestor window.
TString GetDisplayText() const
Returns the text that's currently displayed.
UInt_t fDefWidth
default width
Definition TGTextEntry.h:55
TGGC fNormGC
normal drawing context
Definition TGTextEntry.h:42
~TGTextEntry() override
Delete a text entry widget.
Bool_t fHasOwnFont
kTRUE - font defined locally, kFALSE - globally
Definition TGTextEntry.h:54
void Clear(Option_t *option="") override
Clears up the text entry.
void Deselect()
Deselects all text (i.e.
TBlinkTimer * fCurBlink
cursor blink timer
Definition TGTextEntry.h:46
void CopyText() const
Copies the marked text to the clipboard, if there is any and GetEchoMode() is kNormal.
static TString * fgClipboardText
application clipboard text
Definition TGTextEntry.h:68
virtual void UpdateOffset()
Updates start text offset according GetAlignment() mode, if cursor is out of frame => scroll the text...
TGTextBuffer * GetBuffer() const
const char * GetText() const
Bool_t HandleTimer(TTimer *t) override
Handle cursor blink timer.
virtual void TabPressed()
This signal is emitted when the <TAB> key is pressed.
Bool_t HandleSelectionClear(Event_t *event) override
Handle selection clear event.
void CursorWordBackward(Bool_t mark=kFALSE)
Moves the cursor one word to the left.
virtual void SetCursorPosition(Int_t pos)
Set the cursor position to newPos.
void Backspace()
Deletes the character on the left side of the text cursor and moves the cursor one position to the le...
TString GetMarkedText() const
Returns the text marked by the user (e.g.
Bool_t HandleSelection(Event_t *event) override
Handle text selection event.
void Del()
Deletes the character on the right side of the text cursor.
Bool_t fCursorOn
cursor status (on/off)
Definition TGTextEntry.h:40
static const TGFont * fgDefaultFont
Definition TGTextEntry.h:69
Bool_t HandleDoubleClick(Event_t *event) override
Handle mouse double click event in the text entry widget.
TGToolTip * fTip
associated tooltip
Definition TGTextEntry.h:47
void NewMark(Int_t pos)
New character mark at position pos.
Bool_t IsFrameDrawn() const
static const TGGC & GetDefaultSelectedBackgroundGC()
Return graphics context for highlighted frame background.
TGTextEntry(const TGTextEntry &)=delete
virtual void AppendText(const char *text)
Appends text to the end of text entry, clears the selection and moves the cursor to the end of the li...
virtual void SelectAll()
Selects all text (i.e.
virtual void CursorOutRight()
This signal is emitted when cursor is going out of right side.
void Paste()
Inserts text at the cursor position, deleting any previous marked text.
virtual void SetFrameDrawn(Bool_t flag=kTRUE)
Sets the text entry to draw itself inside a two-pixel frame if enable is kTRUE, and to draw itself wi...
EInsertMode fInsertMode
OPTION={GetMethod="GetInsertMode";SetMethod="SetInsertMode";Items=(kInsert="Insert",...
Definition TGTextEntry.h:52
virtual void SetAlignment(ETextJustification mode=kTextLeft)
Sets the alignment of the text entry.
Int_t fEndIX
selection end in characters
Definition TGTextEntry.h:35
Atom_t fClipboard
clipboard property
Definition TGTextEntry.h:45
virtual void ScrollByChar()
Shift position of cursor by one character.
Int_t GetCharacterIndex(Int_t xcoord)
Returns the index of the character to whose left edge xcoord is closest.
TGGC fSelGC
selected text drawing context
Definition TGTextEntry.h:43
TClass * IsA() const override
EInsertMode GetInsertMode() const
virtual void ShiftTabPressed()
This signal is emitted when SHIFT and TAB keys are pressed.
Int_t fEndX
selection end in pixels
Definition TGTextEntry.h:33
virtual void ReturnPressed()
This signal is emitted when the return or enter key is pressed.
static const TGGC * fgDefaultSelectedGC
Definition TGTextEntry.h:70
GContext_t fSelbackGC
selected background drawing context
Definition TGTextEntry.h:44
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
EEchoMode GetEchoMode() const
ETextJustification fAlignment
OPTION={GetMethod="GetAlignment";SetMethod="SetAlignment";Items=(kTextLeft="Left",...
Definition TGTextEntry.h:53
Bool_t fSelectionOn
selection status (on/off)
Definition TGTextEntry.h:36
Bool_t HandleFocusChange(Event_t *event) override
Handle focus change event in text entry widget.
virtual void SetTextColor(Pixel_t color, Bool_t local=kTRUE)
Changes text color.
void DoRedraw() override
Draw the 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.
Bool_t HandleMotion(Event_t *event) override
Handle mouse motion event in the text entry widget.
FontStruct_t fFontStruct
text font
Definition TGTextEntry.h:41
virtual void CursorOutLeft()
This signal is emitted when cursor is going out of left side.
TGDimension GetDefaultSize() const override
Return the default / minimal size of the widget.
void DrawBorder() override
Draw the border of the text entry widget.
Int_t MaxMark() const
void Cut()
Copies the marked text to the clipboard and deletes it, if there is any.
static const TGGC * fgDefaultGC
Definition TGTextEntry.h:72
void End(Bool_t mark=kFALSE)
Moves the text cursor to the right end of the line.
virtual void InsertText(const char *text, Int_t pos)
Inserts text at position pos, clears the selection and moves the cursor to the end of the line.
virtual void CursorOutDown()
This signal is emitted when cursor is going out of bottom side.
virtual void SetFont(TGFont *font, Bool_t local=kTRUE)
Changes text font specified by pointer to TGFont object.
virtual Bool_t IsCursorOutOfFrame()
Returns kTRUE if cursor is out of frame.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a text entry widget as a C++ statement(s) on output stream out.
virtual void SetInsertMode(EInsertMode mode=kInsert)
Sets the mode how characters are entered to the text entry.
void CursorWordForward(Bool_t mark=kFALSE)
Moves the cursor one word to the right.
virtual void Insert(const char *)
Removes any currently selected text, inserts newText, sets it as the new contents of the text entry.
virtual void Init()
Do default initialization.
Bool_t HandleButton(Event_t *event) override
Handle mouse button event in text entry widget.
Bool_t fEdited
kFALSE, if the line edit's contents have not been changed since the construction
Definition TGTextEntry.h:49
Int_t MinMark() const
void MarkWord(Int_t pos)
Marks the word nearest to cursor position.
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.
virtual void DoubleClicked()
This signal is emitted when widget is double clicked.
virtual void PastePrimary(Window_t wid, Atom_t property, Bool_t del)
Paste text from selection (either primary or cut buffer) into text entry widget.
Int_t fCursorX
cursor position in pixels
Definition TGTextEntry.h:38
static const TGGC & GetDefaultSelectedGC()
Return selection graphics context.
virtual void CursorOutUp()
This signal is emitted when cursor is going out of upper side.
static const TGGC & GetDefaultGC()
Return default graphics context.
Int_t GetMaxLength() const
Int_t fMaxLen
maximum length of text
Definition TGTextEntry.h:48
Int_t fCursorIX
cursor position in characters
Definition TGTextEntry.h:39
Bool_t HandleCrossing(Event_t *event) override
Handle mouse crossing event.
void Remove()
Deletes all characters on the right side of the cursor.
static const TGGC * fgDefaultSelectedBackgroundGC
Definition TGTextEntry.h:71
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.
void Reset()
Reset tool tip popup delay timer.
Int_t fWidgetId
the widget id (used for event processing)
Definition TGWidget.h:46
TString fCommand
command to be executed
Definition TGWidget.h:49
Int_t ClearFlags(Int_t flags)
Definition TGWidget.h:59
Int_t fWidgetFlags
widget status flags (OR of EWidgetStatus)
Definition TGWidget.h:47
Int_t SetFlags(Int_t flags)
Definition TGWidget.h:58
const TGWindow * fMsgWindow
window which handles widget events
Definition TGWidget.h:48
Bool_t IsEnabled() const
Definition TGWidget.h:69
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual void RequestFocus()
request focus
Definition TGWindow.cxx:232
const TGWindow * fParent
Parent window.
Definition TGWindow.h:28
@ kEditDisableHeight
window height cannot be edited
Definition TGWindow.h:62
virtual void SetWindowName(const char *name=nullptr)
Set window name.
Definition TGWindow.cxx:129
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
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:524
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
TString & Insert(Ssiz_t pos, const char *s)
Definition TString.h:661
const char * Data() const
Definition TString.h:376
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
TString & Prepend(const char *cs)
Definition TString.h:673
Bool_t IsNull() const
Definition TString.h:414
TString & Remove(Ssiz_t pos)
Definition TString.h:685
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2356
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition TSystem.cxx:471
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
void Reset()
Reset the timer.
Definition TTimer.cxx:159
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
R__ALWAYS_INLINE bool HasBeenDeleted(const TObject *obj)
Check if the TObject's memory has been deleted.
Definition TObject.h:402
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198
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
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:175
UInt_t fState
key or button mask
Definition GuiTypes.h:181
Int_t fX
Definition GuiTypes.h:178
Time_t fTime
time event event occurred in ms
Definition GuiTypes.h:177
UInt_t fCode
key or button code
Definition GuiTypes.h:180
Longptr_t fUser[5]
5 longs can be used by client message events NOTE: only [0], [1] and [2] may be used.
Definition GuiTypes.h:187
Attributes that can be used when creating or changing a window.
Definition GuiTypes.h:93
Mask_t fMask
bit mask specifying which fields are valid
Definition GuiTypes.h:110
Int_t fWinGravity
one of the window gravity values
Definition GuiTypes.h:100
Int_t fBitGravity
one of bit gravity values
Definition GuiTypes.h:99