45 #include "RConfigure.h" 49 "Text files",
"*.txt",
61 class TGTextEditHist :
public TList {
65 virtual ~TGTextEditHist() {
Delete(); }
79 class TGTextEditCommand :
public TObject {
85 TGTextEditCommand(
TGTextEdit *te) : fEdit(te) {
93 class TInsCharCom :
public TGTextEditCommand {
96 TInsCharCom(
TGTextEdit *te,
char ch) : TGTextEditCommand(te) {
100 fEdit->SetCurrent(fPos);
108 class TDelCharCom :
public TGTextEditCommand {
114 TDelCharCom(
TGTextEdit *te) : TGTextEditCommand(te) {
116 fChar = fEdit->GetText()->GetChar(fPos);
121 fEdit->SetCurrent(fPos);
122 fEdit->InsChar(fChar);
132 class TBreakLineCom :
public TGTextEditCommand {
135 TBreakLineCom(
TGTextEdit *te) : TGTextEditCommand(te) {
142 fEdit->SetCurrent(fPos);
149 class TInsTextCom :
public TGTextEditCommand {
156 TInsTextCom(
TGTextEdit *te) : TGTextEditCommand(te), fChar(0) {
164 fEdit->GetText()->DelText(fPos, fEndPos);
167 fEdit->GetText()->InsChar(fPos, fChar);
168 }
else if (fPos.fY != fEndPos.
fY) {
169 fEdit->GetText()->BreakLine(fPos);
171 fEdit->SetCurrent(fPos);
178 class TDelTextCom :
public TGTextEditCommand {
190 TDelTextCom(
const TDelTextCom &dtc) : TGTextEditCommand(dtc) {
191 fText =
new TGText(dtc.fText);
192 fBreakLine = dtc.fBreakLine;
194 virtual ~TDelTextCom() {
delete fText; }
196 TDelTextCom &operator=(
const TDelTextCom &dtc) {
198 if (fText)
delete fText;
199 fText =
new TGText(dtc.fText);
200 fBreakLine = dtc.fBreakLine;
209 void SetBreakLine(
Bool_t on) { fBreakLine = on; }
213 start_src.
fX = start_src.
fY = 0;
217 fEdit->GetText()->InsText(fPos, fText, start_src, end_src);
221 fEdit->GetText()->BreakLine(fEndPos);
222 fEndPos.
fX = fEdit->GetText()->GetLineLength(fEndPos.
fY);
227 fEdit->SetCurrent(fEndPos);
252 TGTextView(parent, w, h, text, id, sboptions, back)
263 TGTextView(parent, w, h, string, id, sboptions, back)
391 if (untitled || saveas) {
491 if (len < 0) len = 0;
493 buf2 =
new char[len + 2];
494 strncpy(buf2, buf1, (
UInt_t)len);
497 while (buf2[i] !=
'\0') {
498 if (buf2[i] ==
'\t') {
500 while (buf2[j] == 16)
503 strcpy(buf2+i+1, buf2+j);
507 fwrite(buf2,
sizeof(
char), strlen(buf2)+1, p);
516 msg.
Form(
"Printed: %s\nLines: %ld\nUsing: %s -P%s",
546 new TDelCharCom(
this);
556 if (endPos.
fX == -1) {
572 TDelTextCom *dcom =
new TDelTextCom(
this,
fClipText);
574 dcom->SetEndPos(endPos);
583 dcom->SetBreakLine(
kTRUE);
600 th = th < 0 ? 0 : th;
601 ys = ys < 0 ? 0 : ys;
651 msg.
Form(
"Couldn't find \"%s\"",
string);
696 const char *newText,
Bool_t direction,
Bool_t caseSensitive)
699 if (!
fText->
Replace(textPos, oldText, newText, direction, caseSensitive)) {
838 if (count == -1 || count ==
'\t') {
953 if (!nchar)
return kTRUE;
963 start_src.
fY = start_src.
fX = 0;
967 if (end_src.
fX < 0) {
972 TInsTextCom *icom =
new TInsTextCom(
this);
984 if (start_src.
fY == end_src.
fY) {
988 icom->SetEndPos(pos);
1160 if (line[i] ==
' ' || line[i] ==
'\t') {
1161 while (start >= 0) {
1162 if (line[start] ==
' ' || line[start] ==
'\t') --start;
1166 while (end < (
Int_t)len) {
1167 if (line[end] ==
' ' || line[end] ==
'\t') ++end;
1170 }
else if (isalnum(line[i])) {
1171 while (start >= 0) {
1172 if (isalnum(line[start])) --start;
1176 while (end < (
Int_t)len) {
1177 if (isalnum(line[end])) ++end;
1181 while (start >= 0) {
1182 if (isalnum(line[start]) || line[start] ==
' ' || line[start] ==
'\t') {
1189 while (end < (
Int_t)len) {
1190 if (isalnum(line[end]) || line[end] ==
' ' || line[end] ==
'\t') {
1204 char *word =
new char[len + 1];
1206 strncpy(word, line+start, (
UInt_t)len);
1269 gVirtualX->LookupString(event, input,
sizeof(input), keysym);
1287 switch((
EKeySym)keysym & ~0x20) {
1308 new TDelCharCom(
this);
1382 if (n && keysym >= 32 && keysym < 127 &&
1390 new TInsCharCom(
this, input[0]);
1416 new TDelCharCom(
this);
1421 new TBreakLineCom(
this);
1424 new TInsCharCom(
this,
'\t');
1431 new TDelCharCom(
this);
1569 fCanvas, 400, 150, srch, &ret);
1572 this,
"Search(char *,Bool_t,Bool_t)");
1602 msg2.
Form(
"Save \"%s\"?",
1700 printf(
"No action implemented for menu id %ld\n", parm1);
1721 char *charstring = 0;
1724 if (character ==
'\t') {
1729 while (pos.
fX & 0x7) {
1748 new TDelCharCom(
this);
1753 charstring =
new char[2];
1754 charstring[1] =
'\0';
1755 charstring[0] = character;
1768 charstring, strlen(charstring));
1774 if (lineStart < currentLine->GetLineLength()) {
1775 const char *textToRender = currentLine->GetText(lineStart, currentLine->GetLineLength() - lineStart);
1783 delete [] textToRender;
1802 charstring, strlen(charstring));
1806 delete [] charstring;
2204 out <<
" TGTextEdit *";
2207 <<
");"<< std::endl;
2208 if (option && strstr(option,
"keep_names"))
2209 out <<
" " <<
GetName() <<
"->SetName(\"" <<
GetName() <<
"\");" << std::endl;
2212 out <<
" " <<
GetName() <<
"->SetReadOnly(kTRUE);" << std::endl;
2216 out <<
" " <<
GetName() <<
"->EnableMenu(kFALSE);" << std::endl;
2232 txt->
Save(fn.Data());
2234 out <<
" " <<
GetName() <<
"->LoadFile(" << quote << fn.Data() << quote <<
");" << std::endl;
virtual Bool_t HandleKey(Event_t *event)
The key press event handler converts a key press to some line editor action.
static const TGGC & GetCursor1GC()
Return default graphics context for text cursor.
virtual void Print(Option_t *="") const
Send current buffer to printer.
virtual ~TGTextEdit()
Cleanup text edit widget.
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
virtual void Clear(Option_t *="")
Clear text view widget.
virtual void Mark(Long_t xPos, Long_t yPos)
Mark a text region from xPos to yPos.
virtual void CursorOff()
If cursor if on, turn it off.
virtual void UnMark()
Clear marked region.
static TGGC * fgCursor1GC
TGRectangle fExposedRegion
void Reset()
Reset the timer.
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process context menu messages.
Bool_t InsText(TGLongPosition pos, const char *buf)
Insert single line at specified position.
const Mask_t kKeyShiftMask
void Init()
Initiliaze a text edit widget.
void Clear()
Clear text buffer.
R__EXTERN void * gTQSender
TGLongPosition fMarkedEnd
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
virtual void RemoveLast()
Remove the last object of the list.
virtual void SetHsbPosition(Long_t newPos)
Set position of horizontal scrollbar.
virtual void LineUp()
Make current position first line in window by scrolling up.
TGLongPosition fMarkedStart
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
const TGResourcePool * GetResourcePool() const
EInsertMode GetInsertMode() const
virtual Long_t ReturnLongestLineWidth()
Return width of longest line in widget.
Cursor_t GetTextCursor() const
TList * GetHistory() const
virtual Bool_t Copy()
Copy selected text to clipboard.
static Pixel_t fgWhitePixel
virtual void AdjustPos()
Adjust current position.
virtual void Delete(Option_t *="")
Delete selection.
virtual void Clicked(const char *word)
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event in text edit widget.
Bool_t BreakLine(TGLongPosition pos)
Break line at position pos. Returns false if pos is not valid.
virtual FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
virtual Bool_t HandleTimer(TTimer *t)
Handle scroll timer.
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save a text edit widget as a C++ statement(s) on output stream out.
virtual Bool_t Copy()
Copy text.
static TGSearchDialog *& SearchDialog()
Return global search dialog.
TGLongPosition GetCurrentPos() const
virtual Long_t ToObjYCoord(Long_t yCoord)
Convert y screen coordinate to line number.
virtual const char * UnixPathName(const char *unixpathname)
Convert from a Unix pathname to a local pathname.
void SetFunction(EGraphicsFunction v)
Set graphics context drawing function.
Bool_t LoadBuffer(const char *txtbuf)
Load a 0 terminated buffer. Lines will be split at ' '.
TGTextEditHist * fHistory
virtual void ScreenDown()
Move one screen down.
Bool_t DelChar(TGLongPosition pos)
Delete character at specified position pos.
virtual void ScreenUp()
Move one screen up.
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process scrollbar messages.
virtual Long_t ReturnLongestLineWidth()
Return width of longest line.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
TGTextEdit(const TGTextEdit &)
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Bool_t Replace(TGLongPosition start, const char *oldText, const char *newText, Bool_t direction, Bool_t caseSensitive)
Replace oldText by newText. Returns false if nothing replaced.
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Bool_t fEnableCursorWithoutFocus
static char * gPrintCommand
virtual void CursorOn()
Turn cursor on.
static const TGGC & GetDefaultSelectedGC()
Return selection graphics context in use.
static Time_t fgLastClick
virtual void SendMessage(const TGWindow *w, Long_t msg, Long_t parm1, Long_t parm2)
Send message (i.e.
virtual void Update()
update the whole window of text view
char * GetLine(TGLongPosition pos, ULong_t length)
Return string at position pos.
virtual Bool_t LoadFile(const char *fname, long startpos=0, long length=-1)
Load a file in the text view widget.
virtual void End()
Move to end of line.
virtual void SetCurrent(TGLongPosition new_coord)
Make the specified position the current position.
static const TGGC & GetCursor0GC()
Return selection graphics context for text cursor.
virtual void SetMenuState()
Enable/disable menu items in function of what is possible.
const char * GetFileName() const
virtual void DrawCursor(Int_t mode)
Draw cursor. If mode = 1 draw cursor, if mode = 2 erase cursor.
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event in the text editor widget.
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot...
virtual void NextChar()
Go to next character.
R__EXTERN TSystem * gSystem
virtual void Home()
Move to beginning of line.
Bool_t IsEditable() const
virtual TGSearchType * GetType() const
static const char * gFiletypes[]
char * GetWord(ULong_t pos)
Get word at position. Returned string must be deleted.
virtual Bool_t SelectAll()
Select all text in the viewer.
virtual void SetVsbPosition(Long_t newPos)
Set position of vertical scrollbar.
virtual const char * GetName() const
Return unique name, used in SavePrimitive methods.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in text edit widget.
Bool_t Search(TGLongPosition *foundPos, TGLongPosition start, const char *searchString, Bool_t direction, Bool_t caseSensitive)
Search for string searchString starting at the specified position going in forward (direction = true)...
virtual Bool_t HandleFocusChange(Event_t *event)
Handle focus change event in text edit widget.
Handles synchronous and a-synchronous timer events.
virtual Pixel_t GetBackground() const
virtual void DelChar()
Delete a character from the text edit widget.
char GetChar(TGLongPosition pos)
Get character a position pos. If charcater not valid return -1.
virtual void DoubleClicked(const char *word)
Bool_t DelText(TGLongPosition start, TGLongPosition end)
Delete text between start and end positions.
Bool_t Save(const char *fn)
Save text buffer to file fn.
virtual int ClosePipe(FILE *pipe)
Close the pipe.
virtual void Clear(Option_t *="")
Clear text edit widget.
virtual void SetSBRange(Int_t direction)
Set the range for the kVertical or kHorizontal scrollbar.
char * StrDup(const char *str)
Duplicate the string str.
Long_t GetLineLength(Long_t row)
Get length of specified line. Returns -1 if row does not exist.
virtual Bool_t IsMenuEnabled() const
virtual Bool_t HandleSelection(Event_t *event)
Handle selection notify event.
TGLongPosition fScrollVal
virtual Bool_t Replace(TGLongPosition pos, const char *oldText, const char *newText, Bool_t direction, Bool_t caseSensitive)
Replace text starting at textPos.
virtual void InsChar(char character)
Insert a character in the text edit widget.
virtual Bool_t Search(const char *string, Bool_t direction=kTRUE, Bool_t caseSensitive=kFALSE)
Search for string in the specified direction.
virtual void Marked(Bool_t mark)
virtual Bool_t HandleDoubleClick(Event_t *event)
Handle double click event.
virtual void LineDown()
Move one line down.
virtual void UpdateRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
update a part of view
virtual void SetInsertMode(EInsertMode mode=kInsert)
Sets the mode how characters are entered.
Bool_t InsChar(TGLongPosition pos, char c)
Insert character c at the specified position pos.
virtual Bool_t HandleTimer(TTimer *t)
Handle timer cursor blink timer.
virtual Bool_t IsMapped()
Returns kTRUE if window is mapped on screen, kFALSE otherwise.
TGTextLine * GetCurrentLine() const
Bool_t Disconnect(const char *signal=0, void *receiver=0, const char *slot=0)
Disconnects signal of this object from slot of receiver.
virtual void PrevChar()
Go to the previous character.
virtual void DataChanged()
static TGGC * fgCursor0GC
virtual void ScrollCanvas(Int_t newTop, Int_t direction)
Scroll the canvas to new_top in the kVertical or kHorizontal direction.
TString AsString()
Returns content as ROOT string.
Mother of all ROOT objects.
virtual Long_t ToScrXCoord(Long_t xCoord, Long_t line)
Convert column number in specified line to screen coordinate.
virtual Bool_t Cut()
Cut text.
virtual void DrawRegion(Int_t x, Int_t y, UInt_t width, UInt_t height)
Redraw the text edit widget.
Bool_t DelLine(ULong_t pos)
Delete specified row. Returns false if row does not exist.
virtual void ScrollCanvas(Int_t newTop, Int_t direction)
Scroll the canvas to new_top in the kVertical or kHorizontal direction.
virtual void BreakLine()
Break a line.
virtual void Add(TObject *obj)
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
const TGWindow * GetDefaultRoot() const
Returns the root (i.e.
virtual Long_t ToScrYCoord(Long_t yCoord)
Convert line number to screen coordinate.
void ReTab(Long_t row)
Redo all tabs in a line. Needed after a new tab is inserted.
static const TGGC & GetDefaultGC()
Return default graphics context in use.
virtual Bool_t HandleCrossing(Event_t *event)
Handle mouse crossing event.
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
virtual Bool_t Paste()
Paste text into widget.
Bool_t IsReadOnly() const
virtual Bool_t Goto(Long_t line, Long_t column=0)
Goto the specified line.
virtual void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
Draw lines in exposed region.
const Mask_t kKeyControlMask
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
virtual Bool_t SaveFile(const char *fname, Bool_t saveas=kFALSE)
Save file.
char * GetText(ULong_t pos, ULong_t length)
Get length characters from line starting at pos.
virtual Long_t ToObjXCoord(Long_t xCoord, Long_t line)
Convert x screen coordinate to column in specified line.
const char * Data() const
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in text editor.