KaliVeda
Toolkit for HIC analysis
KVTextEntry.cpp
1 /*
2 $Id: KVTextEntry.cpp,v 1.1 2007/12/11 16:03:45 franklan Exp $
3 $Revision: 1.1 $
4 $Date: 2007/12/11 16:03:45 $
5 */
6 
7 //Created by KVClassFactory on Tue Dec 11 14:36:47 2007
8 //Author: John Frankland
9 
10 #include "KVTextEntry.h"
11 #include "TMath.h"
12 
14 
15 //______________________________________________________________________________
16 
17 
23 void KVTextEntry::SetText(const char* text, Bool_t emit)
24 {
25  // Sets text entry to text, clears the selection and moves
26  // the cursor to the end of the line.
27  // Whatever the value of fMaxLen (set with SetMaxLength()),
28  // no truncation takes place, i.e. the text is of unlimited length.
29 
30  TString oldText(GetText());
31 
32  fText->Clear();
33  fText->AddText(0, text); // new text
34 
35  End(kFALSE);
36  if (oldText != GetText()) {
37  if (emit) TextChanged(); // emit signal
38  fClient->NeedRedraw(this);
39  }
40 }
41 
42 
43 
49 
51 {
52  // Set the maximum length of the text in the editor.
53  // Any marked text will be unmarked.
54  // The cursor position is set to 0 and the first part of the
55  // string is shown, but no truncation ever takes place.
56 
57  fMaxLen = maxlen;
58 
60  Deselect();
61 }
62 
63 
64 
68 
69 void KVTextEntry::Insert(const char* newText)
70 {
71  // Removes any currently selected text, inserts newText,
72  // sets it as the new contents of the text entry.
73 
74  TString old(GetText());
75  TString t(newText);
76 
77  if (t.IsNull()) return;
78 
79  for (int i = 0; i < t.Length(); i++) {
80  if (t[i] < ' ') t[i] = ' '; // unprintable/linefeed becomes space
81  }
82 
83  Int_t minP = MinMark();
84  Int_t maxP = MaxMark();
85  Int_t cp = fCursorIX;
86 
87  if (HasMarkedText()) {
88  fText->RemoveText(minP, maxP - minP);
89  cp = minP;
90  }
91 
92  if (fInsertMode == kReplace) fText->RemoveText(cp, t.Length());
93  Int_t ncp = TMath::Min(cp + t.Length(), GetMaxLength());
94  fText->AddText(cp, t.Data());
95 
96  SetCursorPosition(ncp);
97  if (old != GetText()) TextChanged();
98 }
99 
100 
int Int_t
bool Bool_t
constexpr Bool_t kFALSE
Option_t Option_t TPoint TPoint const char text
TGTextEntry without any limit on the length of the text.
Definition: KVTextEntry.h:22
void Insert(const char *) override
Definition: KVTextEntry.cpp:69
void SetMaxLength(Int_t maxlen) override
Definition: KVTextEntry.cpp:50
void AddText(Int_t pos, const char *text)
void RemoveText(Int_t pos, Int_t length)
Bool_t HasMarkedText() const
TGTextBuffer * fText
void Deselect()
const char * GetText() const
virtual void SetCursorPosition(Int_t pos)
EInsertMode fInsertMode
Int_t MaxMark() const
Int_t MinMark() const
virtual void TextChanged(const char *text=nullptr)
Int_t GetMaxLength() const
Int_t fCursorIX
Ssiz_t Length() const
const char * Data() const
Bool_t IsNull() const
void End()
Double_t Min(Double_t a, Double_t b)
ClassImp(TPyArg)