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