44#include "RConfigure.h"
50 "Text files",
"*.txt",
220 start_src.
fX = start_src.
fY = 0;
221 end_src.
fY =
fText->RowCount() - 1;
222 end_src.
fX =
fText->GetLineLength(end_src.
fY) - 1;
308 fMenu->AddSeparator();
312 fMenu->AddSeparator();
314 fMenu->AddSeparator();
319 fMenu->AddSeparator();
324 fMenu->Associate(
this);
334 if (
fText->RowCount() == 1 &&
fText->GetLineLength(0) <= 0) {
397 if (untitled || saveas) {
415 return fText->Save(filename);
432 del = del &&
fClipText->AsString().Length() > 0;
495 while (pos.fY <
fText->RowCount()) {
496 len =
fText->GetLineLength(pos.fY);
497 if (len < 0) len = 0;
498 buf1 =
fText->GetLine(pos, len);
499 buf2 =
new char[len + 2];
500 strncpy(buf2, buf1, (
UInt_t)len);
503 while (buf2[i] !=
'\0') {
504 if (buf2[i] ==
'\t') {
506 while (buf2[j] == 16)
509 strcpy(buf2+i+1, buf2+j);
513 fwrite(buf2,
sizeof(
char), strlen(buf2)+1, p);
522 msg.
Form(
"Printed: %s\nLines: %ld\nUsing: %s -P%s",
523 untitled ?
"Untitled" :
fText->GetFileName(),
562 if (endPos.
fX == -1) {
570 endPos.
fX =
fText->GetLineLength(endPos.
fY);
582 if (delast || ((
fText->GetLineLength(endPos.
fY) == endPos.
fX+1) &&
606 th = th < 0 ? 0 : th;
607 ys = ys < 0 ? 0 : ys;
628 if (
fText->RowCount() == 1 &&
fText->GetLineLength(0) == 0) {
651 if (!
fText->Search(&pos,
fCurrent,
string, direction, caseSensitive)) {
655 if (!
fText->Search(&pos,
fCurrent,
string, direction, caseSensitive)) {
657 msg.
Form(
"Couldn't find \"%s\"",
string);
702 const char *newText,
Bool_t direction,
Bool_t caseSensitive)
705 if (!
fText->Replace(textPos, oldText, newText, direction, caseSensitive)) {
844 if (count == -1 || count ==
'\t') {
959 if (!nchar)
return kTRUE;
969 start_src.
fY = start_src.
fX = 0;
973 if (end_src.
fX < 0) {
990 if (start_src.
fY == end_src.
fY) {
1053 if (pos.fY >=
fText->RowCount()) {
1054 pos.fY =
fText->RowCount()-1;
1057 if (pos.fX >=
fText->GetLineLength(pos.fY)) {
1058 pos.fX =
fText->GetLineLength(pos.fY);
1060 while (
fText->GetChar(pos) == 16) {
1067 char *word =
line->GetWord(pos.fX);
1105 if (!
fText->GetCurrentLine()->GetText()) {
1145 if (pos.fY >=
fText->RowCount()) {
1146 pos.fY =
fText->RowCount() - 1;
1150 if (pos.fX >=
fText->GetLineLength(pos.fY)) {
1151 pos.fX =
fText->GetLineLength(pos.fY);
1153 while (
fText->GetChar(pos) == 16) {
1160 char *
line =
fText->GetCurrentLine()->GetText();
1166 if (
line[i] ==
' ' ||
line[i] ==
'\t') {
1167 while (
start >= 0) {
1172 while (end < (
Int_t)len) {
1173 if (
line[end] ==
' ' ||
line[end] ==
'\t') ++end;
1176 }
else if (isalnum(
line[i])) {
1177 while (
start >= 0) {
1182 while (end < (
Int_t)len) {
1183 if (isalnum(
line[end])) ++end;
1187 while (
start >= 0) {
1195 while (end < (
Int_t)len) {
1196 if (isalnum(
line[end]) ||
line[end] ==
' ' ||
line[end] ==
'\t') {
1210 char *word =
new char[len + 1];
1236 if (pos.fY >=
fText->RowCount()) {
1237 pos.fY =
fText->RowCount()-1;
1240 if (pos.fX >
fText->GetLineLength(pos.fY)) {
1241 pos.fX =
fText->GetLineLength(pos.fY);
1243 if (
fText->GetChar(pos) == 16) {
1250 }
while (
fText->GetChar(pos) == 16);
1275 gVirtualX->LookupString(event, input,
sizeof(input), keysym);
1293 switch((
EKeySym)keysym & ~0x20) {
1377 pos.fY =
fText->RowCount()-1;
1378 pos.fX =
fText->GetLineLength(pos.fY);
1388 if (
n && keysym >= 32 && keysym < 127 &&
1578 this,
"Search(char *,Bool_t,Bool_t)");
1608 msg2.
Form(
"Save \"%s\"?",
1609 untitled ?
"Untitled" :
fText->GetFileName());
1690 msg2.
Form(
"Couldn't find \"%s\"",
fSearch->fBuffer);
1706 printf(
"No action implemented for menu id %zd\n", (
size_t)parm1);
1727 char *charstring = 0;
1730 if (character ==
'\t') {
1733 fText->InsChar(pos,
'\t');
1735 while (pos.fX & 0x7) {
1738 fText->ReTab(pos.fY);
1759 charstring =
new char[2];
1760 charstring[1] =
'\0';
1761 charstring[0] = character;
1774 charstring, strlen(charstring));
1780 if (lineStart < currentLine->GetLineLength()) {
1781 const char *textToRender = currentLine->GetText(lineStart, currentLine->GetLineLength() - lineStart);
1789 delete [] textToRender;
1808 charstring, strlen(charstring));
1812 delete [] charstring;
1839 if (
fText->GetChar(pos) == 16) {
1842 fText->DelChar(pos);
1844 }
while (
fText->GetChar(pos) !=
'\t');
1847 fText->DelChar(pos);
1849 fText->ReTab(pos.fY);
1853 fText->DelChar(pos);
1868 fText->InsText(pos, buffer);
1981 while (
fText->GetChar(pos) == 16) {
1995 len =
fText->GetLineLength(pos.fY);
2073 while (
fText->GetChar(pos) == 16) {
2106 while (
fText->GetChar(pos) == 16) {
2127 while (
fText->GetChar(pos) == 16) {
2147 while (
fText->GetChar(pos) == 16) {
2172 pos.fX =
fText->GetLineLength(pos.fY);
2208 out <<
" TGTextEdit *" <<
GetName() <<
" = new TGTextEdit(" <<
fParent->GetName() <<
"," <<
GetWidth() <<
","
2210 if (option && strstr(option,
"keep_names"))
2211 out <<
" " <<
GetName() <<
"->SetName(\"" <<
GetName() <<
"\");\n";
2214 out <<
" " <<
GetName() <<
"->SetReadOnly(kTRUE);\n";
2217 out <<
" " <<
GetName() <<
"->EnableMenu(kFALSE);\n";
2220 out <<
" " <<
GetName() <<
"->ChangeBackground(" <<
fCanvas->GetBackground() <<
");\n";
2228 fn =
gSystem->UnixPathName(filename);
const Mask_t kKeyShiftMask
const Mask_t kKeyControlMask
ULong_t Pixel_t
Pixel value.
Handle_t Window_t
Window handle.
int Int_t
Signed integer 4 bytes (int).
long Longptr_t
Integer large enough to hold a pointer (platform-dependent).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
bool Bool_t
Boolean (0=false, 1=true) (bool).
const char Option_t
Option string (const char).
static const char * gFiletypes[]
static char * gPrintCommand
char * StrDup(const char *str)
Duplicate the string str.
Bool_t Notify() override
This method must be overridden to handle object notification (the base implementation is no-op).
TBreakLineCom(TGTextEdit *te)
Bool_t Notify() override
This method must be overridden to handle object notification (the base implementation is no-op).
TDelCharCom(TGTextEdit *te)
void SetEndPos(TGLongPosition end)
TDelTextCom(TGTextEdit *te, TGText *txt)
void SetBreakLine(Bool_t on)
TDelTextCom & operator=(const TDelTextCom &dtc)
Bool_t Notify() override
This method must be overridden to handle object notification (the base implementation is no-op).
TDelTextCom(const TDelTextCom &dtc)
This class creates a file selection dialog.
char * fFilename
selected file name
const char ** fFileTypes
file types used to filter selectable files
char * fIniDir
on input: initial directory, on output: new directory
Bool_t fOverwrite
if true overwrite the file with existing name on save
void SetIniDir(const char *inidir)
Set directory name.
virtual Bool_t ProcessMessage(Longptr_t, Longptr_t, Longptr_t)
static Time_t fgLastClick
virtual void SendMessage(const TGWindow *w, Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Send message (i.e.
static Pixel_t fgWhitePixel
void MapRaised() override
map raised
Encapsulate a graphics context used in the low level graphics.
TGClient * fClient
Connection to display server.
Handle_t fId
X11/Win32 Window identifier.
virtual TGSearchType * GetType() const
static TGSearchDialog *& SearchDialog()
Return global search dialog.
void SetPos(TGLongPosition pos)
TGTextEditCommand(TGTextEdit *te)
Bool_t Notify() override
'Notify' all objects in this collection.
~TGTextEditHist() override
A TGTextEdit is a specialization of TGTextView.
TGLongPosition fCurrent
current cursor position
TGTextEditHist * fHistory
undo manager
GContext_t fCursor1GC
graphics context for drawing cursor
TGTextEdit(const TGTextEdit &)=delete
virtual Bool_t Goto(Long_t line, Long_t column=0)
Goto the specified line.
static TGGC * fgCursor0GC
static const TGGC & GetCursor1GC()
Return default graphics context for text cursor.
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 DrawCursor(Int_t mode)
Draw cursor. If mode = 1 draw cursor, if mode = 2 erase cursor.
Bool_t HandleMotion(Event_t *event) override
Handle mouse motion event in text edit widget.
virtual void AdjustPos()
Adjust current position.
virtual Bool_t SaveFile(const char *fname, Bool_t saveas=kFALSE)
Save file.
Bool_t HandleDoubleClick(Event_t *event) override
Handle double click event.
EInsertMode GetInsertMode() const
void Delete(Option_t *="") override
Delete selection.
void ScrollCanvas(Int_t newTop, Int_t direction) override
Scroll the canvas to new_top in the kVertical or kHorizontal direction.
void SavePrimitive(std::ostream &out, Option_t *="") override
Save a text edit widget as a C++ statement(s) on output stream out.
virtual void SetMenuState()
Enable/disable menu items in function of what is possible.
virtual Bool_t Cut()
Cut text.
Bool_t fEnableMenu
enable context menu with editor actions
void Clear(Option_t *="") override
Clear text edit widget.
virtual void DelChar()
Delete a character from the text edit widget.
Bool_t HandleFocusChange(Event_t *event) override
Handle focus change event in text edit widget.
GContext_t fCursor0GC
graphics context for erasing cursor
virtual void LineDown()
Move one line down.
virtual void ScreenDown()
Move one screen down.
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override
Process context menu messages.
Bool_t Copy() override
Copy text.
virtual void LineUp()
Make current position first line in window by scrolling up.
EInsertMode fInsertMode
OPTION={GetMethod="GetInsertMode";SetMethod="SetInsertMode";Items=(kInsert="&Insert",...
virtual void CursorOn()
Turn cursor on.
virtual void SetCurrent(TGLongPosition new_coord)
Make the specified position the current position.
virtual void NextChar()
Go to next character.
virtual void ScreenUp()
Move one screen up.
virtual void BreakLine()
Break a line.
void Print(Option_t *="") const override
Send current buffer to printer.
virtual void InsChar(char character)
Insert a character in the text edit widget.
virtual void SetInsertMode(EInsertMode mode=kInsert)
Sets the mode how characters are entered.
virtual void CursorOff()
If cursor if on, turn it off.
Int_t fCursorState
cursor state (1=drawn, 2=erased)
TGSearchType * fSearch
structure used by search dialog
Bool_t Search(const char *string, Bool_t direction=kTRUE, Bool_t caseSensitive=kFALSE) override
Search for string in the specified direction.
virtual void PrevChar()
Go to the previous character.
virtual Bool_t Paste()
Paste text into widget.
virtual Bool_t IsMenuEnabled() const
Bool_t HandleKey(Event_t *event) override
The key press event handler converts a key press to some line editor action.
void DrawRegion(Int_t x, Int_t y, UInt_t width, UInt_t height) override
Redraw the text edit widget.
TGPopupMenu * fMenu
popup menu with editor actions
~TGTextEdit() override
Cleanup text edit widget.
Bool_t HandleSelection(Event_t *event) override
Handle selection notify event.
Bool_t HandleButton(Event_t *event) override
Handle mouse button event in text edit widget.
Bool_t HandleTimer(TTimer *t) override
Handle timer cursor blink timer.
Long_t ReturnLongestLineWidth() override
Return width of longest line in widget.
Bool_t fEnableCursorWithoutFocus
enable cursor visibility when focus went out from text editor window (default is kTRUE)
virtual void Home()
Move to beginning of line.
Bool_t HandleCrossing(Event_t *event) override
Handle mouse crossing event.
static TGGC * fgCursor1GC
TViewTimer * fCurBlink
cursor blink timer
virtual void End()
Move to end of line.
void Init()
Initialize a text edit widget.
static const TGGC & GetCursor0GC()
Return selection graphics context for text cursor.
Int_t fMaxDescent
maximum descent in font
virtual void Update()
update the whole window of text view
TGGC fNormGC
graphics context for drawing text
Bool_t fReadOnly
text cannot be edited
TGText * fText
text buffer
virtual void UnMark()
Clear marked region.
virtual Long_t ToObjXCoord(Long_t xCoord, Long_t line)
Convert x screen coordinate to column in specified line.
virtual void SetHsbPosition(Long_t newPos)
Set position of horizontal scrollbar.
virtual Bool_t LoadFile(const char *fname, long startpos=0, long length=-1)
Load a file in the text view widget.
virtual void Mark(Long_t xPos, Long_t yPos)
Mark a text region from xPos to yPos.
void DrawRegion(Int_t x, Int_t y, UInt_t w, UInt_t h) override
Draw lines in exposed region.
virtual Long_t ToScrYCoord(Long_t yCoord)
Convert line number to screen coordinate.
virtual Long_t ReturnLongestLineWidth()
Return width of longest line.
Bool_t HandleCrossing(Event_t *event) override
Handle mouse crossing event.
TGText * fClipText
clipboard text buffer
static const TGGC & GetDefaultSelectedGC()
Return selection graphics context in use.
static const TGGC & GetDefaultGC()
Return default graphics context in use.
Bool_t HandleTimer(TTimer *t) override
Handle scroll timer.
Bool_t fIsMarked
true if text is marked/selected
Bool_t HandleMotion(Event_t *event) override
Handle mouse motion event in the text editor widget.
virtual void Clicked(const char *word)
TGGC fSelbackGC
graphics context for drawing marked background
TGGC fSelGC
graphics context for drawing marked text
virtual Bool_t SelectAll()
Select all text in the viewer.
virtual void SetVsbPosition(Long_t newPos)
Set position of vertical scrollbar.
TGLongPosition fMarkedEnd
end position of marked text
virtual Long_t ToScrXCoord(Long_t xCoord, Long_t line)
Convert column number in specified line to screen coordinate.
virtual void Marked(Bool_t mark)
virtual void DataChanged()
Bool_t IsReadOnly() const
virtual Bool_t Copy()
Copy selected text to clipboard.
virtual void DoubleClicked(const char *word)
TGTextView(const TGTextView &)=delete
Bool_t HandleButton(Event_t *event) override
Handle mouse button event in text editor.
virtual void SetSBRange(Int_t direction)
Set the range for the kVertical or kHorizontal scrollbar.
TGLongPosition fMarkedStart
start position of marked text
virtual Long_t ToObjYCoord(Long_t yCoord)
Convert y screen coordinate to line number.
void Clear(Option_t *="") override
Clear text view widget.
A TGText is a multi line text buffer.
Bool_t Save(const char *fn)
Save text buffer to file fn.
const char * GetFileName() const
Atom_t fClipboard
clipboard property
TGHScrollBar * fHsb
horizontal scrollbar
TGVScrollBar * fVsb
vertical scrollbar
TGLongPosition fVisible
position of visible region
Int_t fScrolling
scrolling direction
TGLongPosition fScrollVal
scroll value
TGViewFrame * fCanvas
frame containing the text
virtual void UpdateRegion(Int_t x, Int_t y, UInt_t w, UInt_t h)
update a part of view
virtual void ScrollCanvas(Int_t newTop, Int_t direction)
Scroll the canvas to new_top in the kVertical or kHorizontal direction.
TGRectangle fExposedRegion
exposed area
ROOT GUI Window base class.
const TGWindow * fParent
Parent window.
virtual Bool_t IsMapped()
Returns kTRUE if window is mapped on screen, kFALSE otherwise.
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
TInsCharCom(TGTextEdit *te, char ch)
Bool_t Notify() override
This method must be overridden to handle object notification (the base implementation is no-op).
Bool_t Notify() override
This method must be overridden to handle object notification (the base implementation is no-op).
void SetEndPos(TGLongPosition end)
TInsTextCom(TGTextEdit *te)
TList(const TList &)=delete
TObject * Last() const override
Return the last object in the list. Returns 0 when list is empty.
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
void RemoveLast() override
Remove the last object of the list.
Mother of all ROOT objects.
virtual Bool_t Notify()
This method must be overridden to handle object notification (the base implementation is no-op).
TObject()
TObject constructor.
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.
Bool_t Disconnect(const char *signal=nullptr, void *receiver=nullptr, const char *slot=nullptr)
Disconnects signal of this object from slot of receiver.
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
const char * Data() const
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Handles synchronous and a-synchronous timer events.
TMatrixT< Element > & Add(TMatrixT< Element > &target, Element scalar, const TMatrixT< Element > &source)
Modify addition: target += scalar * source.
EGEventType fType
of event (see EGEventType)
Int_t fY
pointer x, y coordinates in event window
Window_t fWindow
window reported event is relative to
UInt_t fState
key or button mask
Int_t fYRoot
coordinates relative to root
Time_t fTime
time event event occurred in ms
UInt_t fCode
key or button code
Longptr_t fUser[5]
5 longs can be used by client message events NOTE: only [0], [1] and [2] may be used.