Logo ROOT  
Reference Guide
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();
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 ULong_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{
376 UInt_t w = (GetOptions() & kFixedWidth) || (fDefWidth == 0) ? fWidth : fDefWidth;
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
586 fAlignment = mode;
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
600 fInsertMode = mode;
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;
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;
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 {
1018 SetCursorPosition(len);
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);
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 Int_t unknown = 0;
1229
1230 if ((EKeySym)keysym == kKey_Enter || (EKeySym)keysym == kKey_Return) {
1231
1232 ReturnPressed(); // emit signal
1233 if (!TestBit(kNotDeleted)) return kTRUE;
1235
1236 } else if (event->fState & kKeyShiftMask && (EKeySym)keysym == kKey_Backtab) {
1237 ShiftTabPressed(); // emit signal
1239 return kTRUE;
1240
1241 } else if ((EKeySym)keysym == kKey_Tab) {
1242
1243 TabPressed(); // emit signal
1245
1246 } else if (event->fState & kKeyControlMask) { // Cntrl key modifier pressed
1247 switch ((EKeySym)keysym & ~0x20) { // treat upper and lower the same
1248 case kKey_A:
1249 Home(event->fState & kKeyShiftMask);
1250 break;
1251 case kKey_B:
1252 CursorLeft(event->fState & kKeyShiftMask);
1253 break;
1254 case kKey_C:
1255 CopyText();
1256 break;
1257 case kKey_D:
1258 Del();
1259 break;
1260 case kKey_E:
1261 End(event->fState & kKeyShiftMask);
1262 break;
1263 case kKey_F:
1264 CursorRight(event->fState & kKeyShiftMask);
1265 break;
1266 case kKey_H:
1267 Backspace();
1268 break;
1269 case kKey_K:
1270 HasMarkedText() ? Del() : Remove();
1271 break;
1272 case kKey_U:
1273 Home();
1274 Remove();
1275 break;
1276 case kKey_V:
1277 Paste();
1278 break;
1279 case kKey_X:
1280 Cut();
1281 break;
1282 case kKey_Y:
1283 Paste();
1284 break;
1285 case kKey_Right:
1287 break;
1288 case kKey_Left:
1290 break;
1291 default:
1292 unknown++;
1293 }
1294 } else if (n && keysym <127 && keysym >=32 && // printable keys
1295 (EKeySym)keysym != kKey_Delete &&
1296 (EKeySym)keysym != kKey_Backspace) {
1297
1298 Insert(tmp);
1300
1301 } else {
1302 switch ((EKeySym)keysym) {
1303 case kKey_Down:
1304 CursorOutDown();
1305 break;
1306 case kKey_Up:
1307 CursorOutUp();
1308 break;
1309 case kKey_Left:
1310 CursorLeft(event->fState & kKeyShiftMask);
1311 break;
1312 case kKey_Right:
1313 CursorRight(event->fState & kKeyShiftMask);
1314 break;
1315 case kKey_Backspace:
1316 Backspace();
1317 break;
1318 case kKey_Home:
1319 Home(event->fState & kKeyShiftMask);
1320 break;
1321 case kKey_End:
1322 End(event->fState & kKeyShiftMask);
1323 break;
1324 case kKey_Delete:
1325 Del();
1326 break;
1327 case kKey_Insert: // switch on/off insert mode
1329 break;
1330 default:
1331 unknown++;
1332 }
1333 }
1334
1335 UpdateOffset();
1336 fClient->NeedRedraw(this);
1337
1338 return kTRUE;
1339}
1340
1341////////////////////////////////////////////////////////////////////////////////
1342/// Handle mouse button event in text entry widget.
1343
1345{
1346 if (fTip) fTip->Hide();
1347
1348 if (!IsEnabled()) return kTRUE;
1349
1350 if (event->fType == kButtonPress) {
1351 SetFocus();
1352 if (fEchoMode == kNoEcho) return kTRUE;
1353
1354 if (event->fCode == kButton1) {
1355 Int_t offset = IsFrameDrawn() ? 4 : 0;
1356 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
1357 offset = 2;
1358 Int_t x = fOffset + offset;
1359 Int_t position = GetCharacterIndex(event->fX - x);
1361 SetCursorPosition(position);
1362 DoRedraw();
1363 } else if (event->fCode == kButton2) {
1364 if (gVirtualX->GetPrimarySelectionOwner() == kNone) {
1365 // No primary selection, so use the cut buffer
1367 } else {
1368 gVirtualX->ConvertPrimarySelection(fId, fClipboard, event->fTime);
1369 }
1370 }
1371 }
1372 if (event->fType == kButtonRelease)
1373 if (event->fCode == kButton1)
1374 CopyText();
1375
1376 return kTRUE;
1377}
1378
1379////////////////////////////////////////////////////////////////////////////////
1380/// Handle mouse crossing event.
1381
1383{
1384 if (event->fType == kEnterNotify) {
1385 if (fTip) fTip->Reset();
1386 } else {
1387 if (fTip) fTip->Hide();
1388 }
1389
1390 return kTRUE;
1391}
1392
1393////////////////////////////////////////////////////////////////////////////////
1394/// Handle mouse motion event in the text entry widget.
1395
1397{
1398 if (!IsEnabled() || (GetEchoMode() == kNoEcho)) return kTRUE;
1399
1400 Int_t offset = IsFrameDrawn() ? 4 : 0;
1401 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
1402 offset = 2;
1403 Int_t x = fOffset + offset;
1404 Int_t position = GetCharacterIndex(event->fX - x); // + 1;
1406 NewMark(position);
1407 UpdateOffset();
1408 DoRedraw();
1409 return kTRUE;
1410}
1411
1412////////////////////////////////////////////////////////////////////////////////
1413/// Handle mouse double click event in the text entry widget.
1414
1416{
1417 if (!IsEnabled()) return kTRUE;
1418
1419 Int_t offset = IsFrameDrawn() ? 4 : 0;
1420 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
1421 offset = 2;
1422 Int_t x = fOffset + offset ;
1423
1424 DoubleClicked();
1425 SetFocus();
1426 if (fEchoMode == kNoEcho) return kTRUE;
1427
1428 Int_t position = GetCharacterIndex(event->fX - x);
1429 MarkWord(position);
1430 return kTRUE;
1431}
1432
1433////////////////////////////////////////////////////////////////////////////////
1434/// Handles resize events for this widget.
1435
1437{
1439 Bool_t wasSelection = fSelectionOn;
1440 Int_t end = fEndIX, start = fStartIX;
1442 UpdateOffset();
1444 fSelectionOn = wasSelection;
1445 fEndIX = end;
1446 fStartIX = start;
1448 return kTRUE;
1449}
1450
1451////////////////////////////////////////////////////////////////////////////////
1452/// Handle focus change event in text entry widget.
1453
1455{
1456 if (!IsEnabled()) return kTRUE;
1457
1458 // check this when porting to Win32
1459 if (event->fType == kFocusIn) {
1460 fCursorOn = kTRUE;
1461 if (!fCurBlink) fCurBlink = new TBlinkTimer(this, 500);
1462 fCurBlink->Reset();
1463 gBlinkingEntry = this;
1465 } else {
1466 fCursorOn = kFALSE;
1467 // fSelectionOn = kFALSE; // "web browser location behavior"
1468 if (fCurBlink) fCurBlink->Remove();
1469 gBlinkingEntry = 0;
1470 }
1471 fClient->NeedRedraw(this);
1472 return kTRUE;
1473}
1474
1475////////////////////////////////////////////////////////////////////////////////
1476/// Handle text selection event.
1477
1479{
1480 PastePrimary((Window_t)event->fUser[0], (Atom_t)event->fUser[3], kTRUE);
1481 return kTRUE;
1482}
1483
1484////////////////////////////////////////////////////////////////////////////////
1485/// Handle selection clear event.
1486
1488{
1491 fClient->NeedRedraw(this);
1492 return kTRUE;
1493}
1494
1495////////////////////////////////////////////////////////////////////////////////
1496/// Handle request to send current clipboard contents to requestor window.
1497
1499{
1500 Event_t reply;
1501 char *buffer;
1502 Long_t len;
1503 Atom_t targets[2];
1504 Atom_t type;
1505
1506 reply.fType = kSelectionNotify;
1507 reply.fTime = event->fTime;
1508 reply.fUser[0] = event->fUser[0]; // requestor
1509 reply.fUser[1] = event->fUser[1]; // selection
1510 reply.fUser[2] = event->fUser[2]; // target
1511 reply.fUser[3] = event->fUser[3]; // property
1512
1513 targets[0] = gVirtualX->InternAtom("TARGETS", kFALSE);
1514 targets[1] = gVirtualX->InternAtom("XA_STRING", kFALSE);
1515
1516 if ((Atom_t)event->fUser[2] == targets[0]) {
1517 type = gVirtualX->InternAtom("XA_ATOM", kFALSE);
1518 gVirtualX->ChangeProperty((Window_t) event->fUser[0], (Atom_t) event->fUser[3],
1519 type, (UChar_t*) targets, (Int_t) 2);
1520
1521 gVirtualX->SendEvent((Window_t)event->fUser[0], &reply);
1522 return kTRUE;
1523 }
1524
1525 len = 0;
1527 buffer = new char[len+1];
1528 if (fgClipboardText) strlcpy (buffer, fgClipboardText->Data(), len+1);
1529
1530 gVirtualX->ChangeProperty((Window_t) event->fUser[0], (Atom_t) event->fUser[3],
1531 (Atom_t) event->fUser[2], (UChar_t*) buffer,
1532 (Int_t) len);
1533 delete [] buffer;
1534
1535 gVirtualX->SendEvent((Window_t)event->fUser[0], &reply);
1536
1537 return kTRUE;
1538}
1539
1540////////////////////////////////////////////////////////////////////////////////
1541/// Paste text from selection (either primary or cut buffer) into
1542/// text entry widget.
1543
1545{
1546 TString data;
1547 Int_t nchar;
1548
1549 if (!IsEnabled()) return;
1550
1551 gVirtualX->GetPasteBuffer(wid, property, data, nchar, del);
1552
1553 if (nchar) Insert(data.Data());
1554 fClient->NeedRedraw(this);
1555}
1556
1557////////////////////////////////////////////////////////////////////////////////
1558/// Handle cursor blink timer.
1559
1561{
1563 DoRedraw();
1564 return kTRUE;
1565}
1566
1567////////////////////////////////////////////////////////////////////////////////
1568/// Returns kTRUE if cursor is out of frame.
1569
1571{
1572 // fCursorX = fOffset + 4 + gVirtualX->TextWidth(fFontStruct,
1573 // GetDisplayText(), fCursorIX);
1574
1575 Int_t offset = IsFrameDrawn() ? 4 : 0;
1576 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
1577 offset = 2;
1578 Int_t w = GetWidth();
1579 return ((fCursorX < offset) || (fCursorX > w-offset));
1580}
1581
1582////////////////////////////////////////////////////////////////////////////////
1583/// Shift position of cursor by one character.
1584
1586{
1587 if (GetEchoMode() == kNoEcho) return;
1588
1589 TString dt = GetDisplayText();
1590 Int_t len = dt.Length();
1591 Int_t ind = fCursorIX < len-1 ? fCursorIX : len-1;
1592 Int_t charWidth = ind < 0 ? 4 : gVirtualX->TextWidth(fFontStruct, &dt[ind],1);
1593 Int_t w = GetWidth();
1594 Int_t d;
1595 Int_t offset = IsFrameDrawn() ? 4 : 0;
1596 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
1597 offset = 2;
1598
1599 if (fCursorX < offset) {
1600 fOffset += charWidth;
1601 fCursorX += charWidth;
1602 d = fCursorX;
1603
1604 if (d < offset){ // correction
1605 d -= offset;
1606 fOffset -= d;
1607 fCursorX -= d;
1608 }
1609 } else if (fCursorX > w-offset) {
1610 fOffset -= charWidth;
1611 fCursorX -= charWidth;
1612 d = w - fCursorX;
1613
1614 if (d < offset) { // correction
1615 d -= offset;
1616 fOffset += d;
1617 fCursorX += d;
1618 }
1619 }
1620}
1621
1622////////////////////////////////////////////////////////////////////////////////
1623/// Updates start text offset according GetAlignment() mode,
1624/// if cursor is out of frame => scroll the text.
1625/// See also SetAlignment() and ScrollByChar().
1626
1628{
1629 TString dt = GetDisplayText();
1630 Int_t textWidth = gVirtualX->TextWidth(fFontStruct, dt.Data() , dt.Length());
1631 Int_t offset = IsFrameDrawn() ? 4 : 0;
1632 if ((offset == 0) && fParent->InheritsFrom("TGComboBox"))
1633 offset = 2;
1634 Int_t w = GetWidth() - 2 * offset; // subtract border twice
1635
1636 if (fAlignment == kTextRight) fOffset = w - textWidth - 1;
1637 else if (fAlignment == kTextCenterX) fOffset = (w - textWidth)/2;
1638 else if (fAlignment == kTextLeft) fOffset = 0;
1639 if (textWidth > 0 && textWidth > w) { // may need to scroll.
1641 }
1642}
1643
1644////////////////////////////////////////////////////////////////////////////////
1645/// Set tool tip text associated with this text entry. The delay is in
1646/// milliseconds (minimum 250). To remove tool tip call method with
1647/// text = 0.
1648
1649void TGTextEntry::SetToolTipText(const char *text, Long_t delayms)
1650{
1651 if (fTip) {
1652 delete fTip;
1653 fTip = 0;
1654 }
1655
1656 if (text && strlen(text))
1657 fTip = new TGToolTip(fClient->GetDefaultRoot(), this, text, delayms);
1658}
1659
1660////////////////////////////////////////////////////////////////////////////////
1661/// Set focus to this text entry.
1662
1664{
1665 if (gBlinkingEntry && (gBlinkingEntry != this)) {
1667 }
1668 RequestFocus();
1669}
1670
1671////////////////////////////////////////////////////////////////////////////////
1672/// Inserts text at position pos, clears the selection and moves
1673/// the cursor to the end of the line.
1674/// If necessary the text is truncated to fit MaxLength().
1675/// See also GetText(), SetText(), AppendText(), RemoveText().
1676
1677void TGTextEntry::InsertText(const char *text, Int_t pos)
1678{
1679 Int_t position = TMath::Min((Int_t)fText->GetTextLength(), pos);
1680 TString newText(GetText());
1681 newText.Insert(position, text);
1682 SetText(newText.Data());
1683}
1684
1685////////////////////////////////////////////////////////////////////////////////
1686/// Appends text to the end of text entry, clears the selection
1687/// and moves the cursor to the end of the line.
1688/// If necessary the text is truncated to fit MaxLength().
1689/// See also GetText(), InsertText(), SetText(), RemoveText().
1690
1692{
1694}
1695
1696////////////////////////////////////////////////////////////////////////////////
1697/// Removes text at the range, clears the selection and moves
1698/// the cursor to the end of the line.
1699/// See also GetText(), InsertText(), SetText(), AppendText().
1700
1702{
1703 Int_t pos = TMath::Min(start, end);
1704 Int_t len = TMath::Abs(end-start);
1705 TString newText(GetText());
1706 newText.Remove(pos, len);
1707 SetText(newText.Data());
1708}
1709
1710
1711////////////////////////////////////////////////////////////////////////////////
1712/// Changes text font.
1713/// If local is kTRUE font is changed locally.
1714
1716{
1717 if (font == fFontStruct) return;
1718
1719 FontH_t v = gVirtualX->GetFontHandle(font);
1720
1721 if (!v) return;
1722
1723 if (local) {
1724 TGGC *gc = new TGGC(fNormGC); // copy
1726 fNormGC = *gc;
1727 gc = new TGGC(fSelGC); // copy
1728 fSelGC = *gc;
1729 }
1730 fNormGC.SetFont(v);
1731 fSelGC.SetFont(v);
1732 fFontStruct = font;
1733 fClient->NeedRedraw(this);
1734}
1735
1736////////////////////////////////////////////////////////////////////////////////
1737/// Changes text font specified by name.
1738/// If local is kTRUE font is changed locally.
1739
1740void TGTextEntry::SetFont(const char *fontName, Bool_t local)
1741{
1742 TGFont *font = fClient->GetFont(fontName);
1743 if (font) {
1744 SetFont(font->GetFontStruct(), local);
1745 }
1746}
1747
1748////////////////////////////////////////////////////////////////////////////////
1749/// Changes text font specified by pointer to TGFont object.
1750/// If local is kTRUE font is changed locally.
1751
1753{
1754 if (font) {
1755 SetFont(font->GetFontStruct(), local);
1756 }
1757}
1758
1759////////////////////////////////////////////////////////////////////////////////
1760/// Changes text color.
1761/// If local is true color is changed locally.
1762
1764{
1765 if (local) {
1766 TGGC *gc = new TGGC(fNormGC); // copy
1768 fNormGC = *gc;
1769 }
1770
1771 fNormGC.SetForeground(color);
1772 fClient->NeedRedraw(this);
1773}
1774
1775////////////////////////////////////////////////////////////////////////////////
1776/// Changes text color.
1777/// If local is true color is changed locally.
1778
1780{
1781 if (color) {
1782 SetTextColor(color->GetPixel(), local);
1783 }
1784}
1785
1786////////////////////////////////////////////////////////////////////////////////
1787/// Return default font structure in use.
1788
1790{
1791 if (!fgDefaultFont)
1792 fgDefaultFont = gClient->GetResourcePool()->GetDefaultFont();
1793 return fgDefaultFont->GetFontStruct();
1794}
1795
1796////////////////////////////////////////////////////////////////////////////////
1797/// Return default graphics context.
1798
1800{
1801 if (!fgDefaultGC)
1802 fgDefaultGC = gClient->GetResourcePool()->GetFrameGC();
1803 return *fgDefaultGC;
1804}
1805
1806////////////////////////////////////////////////////////////////////////////////
1807/// Return selection graphics context.
1808
1810{
1812 fgDefaultSelectedGC = gClient->GetResourcePool()->GetSelectedGC();
1813 return *fgDefaultSelectedGC;
1814}
1815
1816////////////////////////////////////////////////////////////////////////////////
1817/// Return graphics context for highlighted frame background.
1818
1820{
1822 fgDefaultSelectedBackgroundGC = gClient->GetResourcePool()->GetSelectedBckgndGC();
1824}
1825
1826////////////////////////////////////////////////////////////////////////////////
1827/// Save a text entry widget as a C++ statement(s) on output stream out.
1828
1829void TGTextEntry::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
1830{
1831 char quote = '"';
1832
1833 // font + GC
1834 option = GetName()+5; // unique digit id of the name
1835 TString parGC, parFont;
1836 // coverity[returned_null]
1837 // coverity[dereference]
1838 parFont.Form("%s::GetDefaultFontStruct()",IsA()->GetName());
1839 // coverity[returned_null]
1840 // coverity[dereference]
1841 parGC.Form("%s::GetDefaultGC()()",IsA()->GetName());
1842
1843 if ((GetDefaultFontStruct() != fFontStruct) || (GetDefaultGC()() != fNormGC.GetGC())) {
1844 TGFont *ufont = gClient->GetResourcePool()->GetFontPool()->FindFont(fFontStruct);
1845 if (ufont) {
1846 ufont->SavePrimitive(out, option);
1847 parFont.Form("ufont->GetFontStruct()");
1848 }
1849
1850 TGGC *userGC = gClient->GetResourcePool()->GetGCPool()->FindGC(fNormGC.GetGC());
1851 if (userGC) {
1852 userGC->SavePrimitive(out, option);
1853 parGC.Form("uGC->GetGC()");
1854 }
1855 }
1856
1857 if (fBackground != GetWhitePixel()) SaveUserColor(out, option);
1858
1859 out << " TGTextEntry *";
1860 out << GetName() << " = new TGTextEntry(" << fParent->GetName()
1861 << ", new TGTextBuffer(" << GetBuffer()->GetBufferLength() << ")";
1862
1863 if (fBackground == GetWhitePixel()) {
1864 if (GetOptions() == (kSunkenFrame | kDoubleBorder)) {
1866 if (fNormGC() == GetDefaultGC()()) {
1867 if (fWidgetId == -1) {
1868 out <<");" << std::endl;
1869 } else {
1870 out << "," << fWidgetId << ");" << std::endl;
1871 }
1872 } else {
1873 out << "," << fWidgetId << "," << parGC.Data() << ");" << std::endl;
1874 }
1875 } else {
1876 out << "," << fWidgetId << "," << parGC.Data() << "," << parFont.Data()
1877 <<");" << std::endl;
1878 }
1879 } else {
1880 out << "," << fWidgetId << "," << parGC.Data() << "," << parFont.Data()
1881 << "," << GetOptionString() << ");" << std::endl;
1882 }
1883 } else {
1884 out << "," << fWidgetId << "," << parGC.Data() << "," << parFont.Data()
1885 << "," << GetOptionString() << ",ucolor);" << std::endl;
1886 }
1887 if (option && strstr(option, "keep_names"))
1888 out << " " << GetName() << "->SetName(\"" << GetName() << "\");" << std::endl;
1889
1890 out << " " << GetName() << "->SetMaxLength(" << GetMaxLength() << ");" << std::endl;
1891
1892 out << " " << GetName() << "->SetAlignment(";
1893
1894 if (fAlignment == kTextLeft)
1895 out << "kTextLeft);" << std::endl;
1896
1897 if (fAlignment == kTextRight)
1898 out << "kTextRight);" << std::endl;
1899
1900 if (fAlignment == kTextCenterX)
1901 out << "kTextCenterX);" << std::endl;
1902
1903 out << " " << GetName() << "->SetText(" << quote << GetText() << quote
1904 << ");" << std::endl;
1905
1906 out << " " << GetName() << "->Resize("<< GetWidth() << "," << GetName()
1907 << "->GetDefaultHeight());" << std::endl;
1908
1909 if ((fDefWidth > 0) || (fDefHeight > 0)) {
1910 out << " " << GetName() << "->SetDefaultSize(";
1911 out << fDefWidth << "," << fDefHeight << ");" << std::endl;
1912 }
1913
1914 if (fTip) {
1915 TString tiptext = fTip->GetText()->GetString();
1916 tiptext.ReplaceAll("\n", "\\n");
1917 out << " ";
1918 out << GetName() << "->SetToolTipText(" << quote
1919 << tiptext << quote << ");" << std::endl;
1920 }
1921}
@ 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
const Mask_t kWAWinGravity
Definition: GuiTypes.h:145
const Mask_t kAnyModifier
Definition: GuiTypes.h:210
const Mask_t kKeyPressMask
Definition: GuiTypes.h:159
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
Handle_t Atom_t
WM token.
Definition: GuiTypes.h:37
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
Handle_t GContext_t
Graphics context handle.
Definition: GuiTypes.h:38
const Mask_t kButtonReleaseMask
Definition: GuiTypes.h:162
const Mask_t kEnterWindowMask
Definition: GuiTypes.h:167
Handle_t FontStruct_t
Pointer to font structure.
Definition: GuiTypes.h:39
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 Window_t
Window handle.
Definition: GuiTypes.h:29
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
int Int_t
Definition: RtypesCore.h:45
unsigned char UChar_t
Definition: RtypesCore.h:38
unsigned int UInt_t
Definition: RtypesCore.h:46
const Bool_t kFALSE
Definition: RtypesCore.h:101
unsigned long ULong_t
Definition: RtypesCore.h:55
long Long_t
Definition: RtypesCore.h:54
bool Bool_t
Definition: RtypesCore.h:63
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:364
#define gClient
Definition: TGClient.h:157
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
XFontStruct * id
Definition: TGX11.cxx:109
int type
Definition: TGX11.cxx:121
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
#define gVirtualX
Definition: TVirtualX.h:338
Int_t MK_MSG(EWidgetMessageTypes msg, EWidgetMessageTypes submsg)
@ kTE_TEXTCHANGED
@ kTE_ENTER
@ kTE_TAB
@ kC_TEXTENTRY
TGTextEntry * fTextEntry
Bool_t Notify()
Notify when timer times out and reset the timer.
TBlinkTimer(TGTextEntry *t, Long_t ms)
The color creation and management class.
Definition: TColor.h:19
ULong_t GetPixel() const
Return pixel value corresponding to this color.
Definition: TColor.cxx:1446
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
Definition: TGClient.cxx:236
void ProcessLine(TString cmd, Long_t msg, Long_t parm1, Long_t parm2)
Execute string "cmd" via the interpreter.
Definition: TGClient.cxx:916
TGFont * GetFont(const char *font, Bool_t fixedDefault=kTRUE)
Get a font from the font pool.
Definition: TGClient.cxx:350
const TGResourcePool * GetResourcePool() const
Definition: TGClient.h:124
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:374
Encapsulate fonts used in the GUI system.
Definition: TGFont.h:140
FontStruct_t GetFontStruct() const
Definition: TGFont.h:184
virtual void SavePrimitive(std::ostream &out, Option_t *="")
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
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
static const TGGC & GetHilightGC()
Get highlight color graphics context.
Definition: TGFrame.cxx:755
virtual void SetBackgroundColor(Pixel_t back)
Set background color (override from TGWindow base class).
Definition: TGFrame.cxx:312
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
Definition: TGFrame.cxx:645
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:2504
static const TGGC & GetShadowGC()
Get shadow color graphics context.
Definition: TGFrame.cxx:765
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:605
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:2477
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 SavePrimitive(std::ostream &out, Option_t *option="")
Save graphics context info as a C++ statement(s) on output stream out.
Definition: TGGC.cxx:627
void SetFont(FontH_t v)
Set font.
Definition: TGGC.cxx:411
void SetForeground(Pixel_t v)
Set foreground color.
Definition: TGGC.cxx:278
TGClient * fClient
Connection to display server.
Definition: TGObject.h:27
Handle_t GetId() const
Definition: TGObject.h:37
Handle_t fId
X11/Win32 Window identifier.
Definition: TGObject.h:26
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.
Definition: TGTextBuffer.h:19
UInt_t GetBufferLength() const
Definition: TGTextBuffer.h:33
void AddText(Int_t pos, const char *text)
Definition: TGTextBuffer.h:36
const char * GetString() const
Definition: TGTextBuffer.h:34
void RemoveText(Int_t pos, Int_t length)
Definition: TGTextBuffer.h:38
UInt_t GetTextLength() const
Definition: TGTextBuffer.h:32
void Clear()
Definition: TGTextBuffer.h:39
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.
virtual Bool_t HandleKey(Event_t *event)
The key press event handler converts a key press to some line editor action.
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
Definition: TGTextEntry.h:122
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
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
virtual Bool_t HandleSelectionRequest(Event_t *event)
Handle request to send current clipboard contents to requestor window.
TGTextBuffer * fText
text buffer
Definition: TGTextEntry.h:31
TString GetDisplayText() const
Returns the text that's currently displayed.
UInt_t fDefWidth
default width
Definition: TGTextEntry.h:55
virtual ~TGTextEntry()
Delete a text entry widget.
virtual Bool_t HandleConfigureNotify(Event_t *event)
Handles resize events for this widget.
TGGC fNormGC
normal drawing context
Definition: TGTextEntry.h:42
Bool_t fHasOwnFont
kTRUE - font defined locally, kFALSE - globally
Definition: TGTextEntry.h:54
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.
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
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
Definition: TGTextEntry.h:112
const char * GetText() const
Definition: TGTextEntry.h:119
virtual void TabPressed()
This signal is emitted when the <TAB> key is pressed.
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.
virtual Bool_t HandleFocusChange(Event_t *event)
Handle focus change event in text entry widget.
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
TGToolTip * fTip
associated tooltip
Definition: TGTextEntry.h:47
virtual Bool_t HandleTimer(TTimer *t)
Handle cursor blink timer.
void NewMark(Int_t pos)
New character mark at position pos.
Bool_t IsFrameDrawn() const
Definition: TGTextEntry.h:128
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event in the text entry widget.
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 SavePrimitive(std::ostream &out, Option_t *option="")
Save a text entry widget as a C++ statement(s) on output stream out.
virtual void SelectAll()
Selects all text (i.e.
virtual void CursorOutRight()
This signal is emitted when cursor is going out of right side.
virtual Bool_t HandleSelectionClear(Event_t *event)
Handle selection clear event.
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
EInsertMode GetInsertMode() const
Definition: TGTextEntry.h:116
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
Definition: TGTextEntry.h:115
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
virtual void SetTextColor(Pixel_t color, Bool_t local=kTRUE)
Changes text color.
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
virtual void CursorOutLeft()
This signal is emitted when cursor is going out of left side.
virtual TGDimension GetDefaultSize() const
Return the default / minimal size of the widget.
Int_t MaxMark() const
Definition: TGTextEntry.h:132
void Clear(Option_t *option="")
Clears up the text entry.
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.
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.
virtual Bool_t HandleSelection(Event_t *event)
Handle text selection event.
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
Definition: TGTextEntry.h:133
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 Bool_t HandleDoubleClick(Event_t *event)
Handle mouse double click event in the text entry widget.
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in text entry widget.
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
Definition: TGTextEntry.h:118
Int_t fMaxLen
maximum length of text
Definition: TGTextEntry.h:48
Int_t fCursorIX
cursor position in characters
Definition: TGTextEntry.h:39
virtual void DoRedraw()
Draw the text entry widget.
virtual void DrawBorder()
Draw the border of the text entry widget.
void Remove()
Deletes all characters on the right side of the cursor.
static const TGGC * fgDefaultSelectedBackgroundGC
Definition: TGTextEntry.h:71
void Hide()
Hide tool tip window.
Definition: TGToolTip.cxx:250
const TGString * GetText() const
Get the tool tip text.
Definition: TGToolTip.cxx:430
void Reset()
Reset tool tip popup delay timer.
Definition: TGToolTip.cxx:263
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 SetWindowName(const char *name=0)
Set window name.
Definition: TGWindow.cxx:129
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
Definition: TGWindow.cxx:336
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:55
UInt_t fEditDisabled
flags used for "guibuilding"
Definition: TGWindow.h:32
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:187
@ kNotDeleted
object has not been deleted
Definition: TObject.h:78
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
Basic string class.
Definition: TString.h:136
Ssiz_t Length() const
Definition: TString.h:410
TString & Insert(Ssiz_t pos, const char *s)
Definition: TString.h:649
const char * Data() const
Definition: TString.h:369
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
TString & Prepend(const char *cs)
Definition: TString.h:661
Bool_t IsNull() const
Definition: TString.h:407
TString & Remove(Ssiz_t pos)
Definition: TString.h:673
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2314
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
void Reset()
Reset the timer.
Definition: TTimer.cxx:157
void Remove()
Definition: TTimer.h:86
TText * text
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
static constexpr double ms
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180
Short_t Abs(Short_t d)
Definition: TMathBase.h:120
Event structure.
Definition: GuiTypes.h:174
EGEventType fType
of event (see EGEventType)
Definition: GuiTypes.h:175
Time_t fTime
time event event occurred in ms
Definition: GuiTypes.h:177
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
#define mark(osub)
Definition: triangle.c:1207
void ws()
Definition: ws.C:66