KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
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
13
14//______________________________________________________________________________
15
16
21
22void KVTextEntry::SetText(const char* text, Bool_t emit)
23{
24 // Sets text entry to text, clears the selection and moves
25 // the cursor to the end of the line.
26 // Whatever the value of fMaxLen (set with SetMaxLength()),
27 // no truncation takes place, i.e. the text is of unlimited length.
28
29 TString oldText(GetText());
30
31 fText->Clear();
32 fText->AddText(0, text); // new text
33
34 End(kFALSE);
35 if (oldText != GetText()) {
36 if (emit) TextChanged(); // emit signal
37 fClient->NeedRedraw(this);
38 }
39}
40
41
42
48
50{
51 // Set the maximum length of the text in the editor.
52 // Any marked text will be unmarked.
53 // The cursor position is set to 0 and the first part of the
54 // string is shown, but no truncation ever takes place.
55
56 fMaxLen = maxlen;
57
59 Deselect();
60}
61
62
63
67
68void KVTextEntry::Insert(const char* newText)
69{
70 // Removes any currently selected text, inserts newText,
71 // sets it as the new contents of the text entry.
72
73 TString old(GetText());
74 TString t(newText);
75
76 if (t.IsNull()) return;
77
78 for (int i = 0; i < t.Length(); i++) {
79 if (t[i] < ' ') t[i] = ' '; // unprintable/linefeed becomes space
80 }
81
82 Int_t minP = MinMark();
83 Int_t maxP = MaxMark();
84 Int_t cp = fCursorIX;
85
86 if (HasMarkedText()) {
87 fText->RemoveText(minP, maxP - minP);
88 cp = minP;
89 }
90
91 if (fInsertMode == kReplace) fText->RemoveText(cp, t.Length());
92 Int_t ncp = TMath::Min(cp + t.Length(), GetMaxLength());
93 fText->AddText(cp, t.Data());
94
96 if (old != GetText()) TextChanged();
97}
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
virtual void SetMaxLength(Int_t maxlen)
virtual void Insert(const char *)
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)