/*
<img src="gif/TGTextEditor.gif">
*/
//End_Html
#include "TROOT.h"
#include "TSystem.h"
#include "TMacro.h"
#include "TInterpreter.h"
#include "TGMsgBox.h"
#include "TGFileDialog.h"
#include "TGFontDialog.h"
#include "TGTextEdit.h"
#include "TGMenu.h"
#include "TGButton.h"
#include "TGStatusBar.h"
#include "KeySymbols.h"
#include "TGToolBar.h"
#include "TG3DLine.h"
#include "TGLabel.h"
#include "TGTextEntry.h"
#include "TGTextEditDialogs.h"
#include "TGTextEditor.h"
#include "TGComboBox.h"
#include "TObjString.h"
#include "TRootHelpDialog.h"
#include "HelpText.h"
#ifdef WIN32
#include "TWin32SplashThread.h"
#endif
const char *ed_filetypes[] = {
"ROOT Macros", "*.C",
"Source files", "*.cxx",
"Text files", "*.txt",
"All files", "*",
0, 0
};
enum ETextEditorCommands {
kM_FILE_NEW, kM_FILE_OPEN, kM_FILE_SAVE, kM_FILE_SAVEAS, kM_FILE_PRINT,
kM_FILE_EXIT, kM_EDIT_CUT, kM_EDIT_COPY, kM_EDIT_PASTE, kM_EDIT_DELETE,
kM_EDIT_SELECTALL, kM_SEARCH_FIND, kM_SEARCH_FINDNEXT, kM_SEARCH_GOTO,
kM_TOOLS_COMPILE, kM_TOOLS_EXECUTE, kM_TOOLS_INTERRUPT, kM_HELP_CONTENTS,
kM_HELP_ABOUT, kM_EDIT_SELFONT
};
ToolBarData_t fTbData[] = {
{ "ed_new.png", "New File", kFALSE, kM_FILE_NEW, 0 },
{ "ed_open.png", "Open File", kFALSE, kM_FILE_OPEN, 0 },
{ "ed_save.png", "Save File", kFALSE, kM_FILE_SAVE, 0 },
{ "ed_saveas.png", "Save File As...", kFALSE, kM_FILE_SAVEAS, 0 },
{ "", 0, 0, -1, 0 },
{ "ed_print.png", "Print", kFALSE, kM_FILE_PRINT, 0 },
{ "", 0, 0, -1, 0 },
{ "ed_cut.png", "Cut selection", kFALSE, kM_EDIT_CUT, 0 },
{ "ed_copy.png", "Copy selection", kFALSE, kM_EDIT_COPY, 0 },
{ "ed_paste.png", "Paste selection", kFALSE, kM_EDIT_PASTE, 0 },
{ "ed_delete.png", "Delete selection", kFALSE, kM_EDIT_DELETE, 0 },
{ "", 0, 0, -1, 0 },
{ "ed_find.png", "Find...", kFALSE, kM_SEARCH_FIND, 0 },
{ "ed_findnext.png", "Find next", kFALSE, kM_SEARCH_FINDNEXT, 0 },
{ "ed_goto.png", "Goto...", kFALSE, kM_SEARCH_GOTO, 0 },
{ "", 0, 0, -1, 0 },
{ "ed_compile.png", "Compile Macro", kFALSE, kM_TOOLS_COMPILE, 0 },
{ "ed_execute.png", "Execute Macro", kFALSE, kM_TOOLS_EXECUTE, 0 },
{ "ed_interrupt.png", "Interrupt", kFALSE, kM_TOOLS_INTERRUPT, 0 },
{ "", 0, 0, -1, 0 },
{ "ed_help.png", "Help Contents", kFALSE, kM_HELP_CONTENTS, 0 },
{ "", 0, 0, -1, 0 },
{ "ed_quit.png", "Close Editor", kFALSE, kM_FILE_EXIT, 0 },
{ 0, 0, 0, 0, 0 }
};
static char *gEPrinter = 0;
static char *gEPrintCommand = 0;
ClassImp(TGTextEditor)
TGTextEditor::TGTextEditor(const char *filename, const TGWindow *p, UInt_t w,
UInt_t h) : TGMainFrame(p, w, h)
{
Build();
if (p && p != gClient->GetDefaultRoot()) {
fComboCmd->UnmapWindow();
fToolBar->RemoveFrame(fComboCmd);
fLabel->UnmapWindow();
fToolBar->RemoveFrame(fLabel);
fToolBar->GetButton(kM_FILE_EXIT)->SetState(kButtonDisabled);
fToolBar->Layout();
}
if (filename) {
LoadFile((char *)filename);
}
MapWindow();
}
TGTextEditor::TGTextEditor(TMacro *macro, const TGWindow *p, UInt_t w, UInt_t h) :
TGMainFrame(p, w, h)
{
char tmp[1024];
Build();
if (p && p != gClient->GetDefaultRoot()) {
fComboCmd->UnmapWindow();
fLabel->UnmapWindow();
fToolBar->GetButton(kM_FILE_EXIT)->SetState(kButtonDisabled);
fToolBar->Layout();
}
if (macro) {
fMacro = macro;
TIter next(macro->GetListOfLines());
TObjString *obj;
while ((obj = (TObjString*) next())) {
fTextEdit->AddLine(obj->GetName());
}
sprintf(tmp, "TMacro : %s: %ld lines read.",
macro->GetName(), fTextEdit->ReturnLineCount());
fStatusBar->SetText(tmp, 0);
fFilename = macro->GetName();
fFilename += ".C";
sprintf(tmp, "TMacro : %s - TGTextEditor", macro->GetName());
SetWindowName(tmp);
}
MapWindow();
}
TGTextEditor::~TGTextEditor()
{
if (fTimer) delete fTimer;
if (fMenuFile) delete fMenuFile;
if (fMenuEdit) delete fMenuEdit;
if (fMenuSearch) delete fMenuSearch;
if (fMenuTools) delete fMenuTools;
if (fMenuHelp) delete fMenuHelp;
}
void TGTextEditor::DeleteWindow()
{
delete fTimer; fTimer = 0;
delete fMenuFile; fMenuFile = 0;
delete fMenuEdit; fMenuEdit = 0;
delete fMenuSearch; fMenuSearch = 0;
delete fMenuTools; fMenuTools = 0;
delete fMenuHelp; fMenuHelp = 0;
Cleanup();
TGMainFrame::DeleteWindow();
}
void TGTextEditor::Build()
{
SetCleanup(kDeepCleanup);
fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 1, 1);
fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
fMenuFile = new TGPopupMenu(fClient->GetDefaultRoot());
fMenuFile->AddEntry("&New", kM_FILE_NEW);
fMenuFile->AddSeparator();
fMenuFile->AddEntry("&Open...", kM_FILE_OPEN);
fMenuFile->AddEntry("&Save", kM_FILE_SAVE);
fMenuFile->AddEntry("Save &As...", kM_FILE_SAVEAS);
fMenuFile->AddSeparator();
fMenuFile->AddEntry("&Print...", kM_FILE_PRINT);
fMenuFile->AddSeparator();
fMenuFile->AddEntry("E&xit", kM_FILE_EXIT);
fMenuEdit = new TGPopupMenu(fClient->GetDefaultRoot());
fMenuEdit->AddEntry("Cu&t\tCtrl+X", kM_EDIT_CUT);
fMenuEdit->AddEntry("&Copy\tCtrl+C", kM_EDIT_COPY);
fMenuEdit->AddEntry("&Paste\tCtrl+V", kM_EDIT_PASTE);
fMenuEdit->AddEntry("De&lete\tDel", kM_EDIT_DELETE);
fMenuEdit->AddSeparator();
fMenuEdit->AddEntry("Select &All\tCtrl+A", kM_EDIT_SELECTALL);
fMenuEdit->AddSeparator();
fMenuEdit->AddEntry("Set &Font", kM_EDIT_SELFONT);
fMenuTools = new TGPopupMenu(fClient->GetDefaultRoot());
fMenuTools->AddEntry("&Compile Macro\tCtrl+F7", kM_TOOLS_COMPILE);
fMenuTools->AddEntry("&Execute Macro\tCtrl+F5", kM_TOOLS_EXECUTE);
fMenuTools->AddEntry("&Interrupt\tShift+F5", kM_TOOLS_INTERRUPT);
fMenuEdit->DisableEntry(kM_EDIT_CUT);
fMenuEdit->DisableEntry(kM_EDIT_COPY);
fMenuEdit->DisableEntry(kM_EDIT_DELETE);
fMenuEdit->DisableEntry(kM_EDIT_PASTE);
fMenuSearch = new TGPopupMenu(fClient->GetDefaultRoot());
fMenuSearch->AddEntry("&Find...\tCtrl+F", kM_SEARCH_FIND);
fMenuSearch->AddEntry("Find &Next\tF3", kM_SEARCH_FINDNEXT);
fMenuSearch->AddSeparator();
fMenuSearch->AddEntry("&Goto Line...\tCtrl+L", kM_SEARCH_GOTO);
fMenuHelp = new TGPopupMenu(fClient->GetDefaultRoot());
fMenuHelp->AddEntry("&Help Topics\tF1", kM_HELP_CONTENTS);
fMenuHelp->AddSeparator();
fMenuHelp->AddEntry("&About...", kM_HELP_ABOUT);
fMenuFile->Associate(this);
fMenuEdit->Associate(this);
fMenuSearch->Associate(this);
fMenuTools->Associate(this);
fMenuHelp->Associate(this);
fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
fMenuBar->SetCleanup(kDeepCleanup);
fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout);
fMenuBar->AddPopup("&Edit", fMenuEdit, fMenuBarItemLayout);
fMenuBar->AddPopup("&Search", fMenuSearch, fMenuBarItemLayout);
fMenuBar->AddPopup("&Tools", fMenuTools, fMenuBarItemLayout);
fMenuBar->AddPopup("&Help", fMenuHelp, new TGLayoutHints(kLHintsTop |
kLHintsRight));
AddFrame(fMenuBar, fMenuBarLayout);
AddFrame(new TGHorizontal3DLine(this),
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,0,2,2));
Int_t i,spacing = 8;
fToolBar = new TGToolBar(this, 60, 20, kHorizontalFrame);
fToolBar->SetCleanup(kDeepCleanup);
for (i = 0; fTbData[i].fPixmap; i++) {
if (strlen(fTbData[i].fPixmap) == 0) {
spacing = 8;
continue;
}
fToolBar->AddButton(this, &fTbData[i], spacing);
spacing = 0;
}
fComboCmd = new TGComboBox(fToolBar, "");
fCommand = fComboCmd->GetTextEntry();
fCommandBuf = fCommand->GetBuffer();
fCommand->Associate(this);
fComboCmd->Resize(200, fCommand->GetDefaultHeight());
fToolBar->AddFrame(fComboCmd, new TGLayoutHints(kLHintsCenterY |
kLHintsRight, 5, 5, 1, 1));
fToolBar->AddFrame(fLabel = new TGLabel(fToolBar, "Command :"),
new TGLayoutHints(kLHintsCenterY | kLHintsRight, 5, 5, 1, 1));
AddFrame(fToolBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
0, 0, 0, 0));
AddFrame(new TGHorizontal3DLine(this),
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0,0,2,2));
fToolBar->GetButton(kM_EDIT_CUT)->SetState(kButtonDisabled);
fToolBar->GetButton(kM_EDIT_COPY)->SetState(kButtonDisabled);
fToolBar->GetButton(kM_EDIT_DELETE)->SetState(kButtonDisabled);
fToolBar->GetButton(kM_EDIT_PASTE)->SetState(kButtonDisabled);
fTextEdit = new TGTextEdit(this, 10, 10, 1);
Pixel_t pxl;
gClient->GetColorByName("#ccccff", pxl);
fTextEdit->SetSelectBack(pxl);
fTextEdit->SetSelectFore(TGFrame::GetBlackPixel());
fTextEdit->Associate(this);
AddFrame(fTextEdit, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
Int_t parts[] = { 75, 25 };
fStatusBar = new TGStatusBar(this);
fStatusBar->SetCleanup(kDeepCleanup);
fStatusBar->SetParts(parts, 2);
AddFrame(fStatusBar, new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 0, 0, 3, 0));
SetClassHints("TGTextEditor", "TGTextEditor");
SetWindowName("Untitled - TGTextEditor");
fMacro = 0;
fFilename = "Untitled";
fStatusBar->SetText(fFilename.Data(), 0);
fTextEdit->SetFocus();
fTextEdit->Connect("DataChanged()", "TGTextEditor", this, "DataChanged()");
fTextEdit->Connect("DataDropped(char *)", "TGTextEditor", this, "DataDropped(char *)");
fTextEdit->MapWindow();
MapSubwindows();
Resize(GetDefaultWidth() + 50, GetDefaultHeight() > 500 ? GetDefaultHeight() : 500);
Layout();
gVirtualX->GrabKey(fId, gVirtualX->KeysymToKeycode(kKey_F3), 0, kTRUE);
AddInput(kKeyPressMask | kEnterWindowMask | kLeaveWindowMask |
kFocusChangeMask | kStructureNotifyMask);
fTimer = new TTimer(this, 250);
fTimer->Reset();
fTimer->TurnOn();
fExiting = kFALSE;
fTextChanged = kFALSE;
}
void TGTextEditor::DataDropped(char *fname)
{
char tmp[1024];
fFilename = fname;
sprintf(tmp, "%s: %ld lines read.", fname, fTextEdit->ReturnLineCount());
fStatusBar->SetText(tmp, 0);
sprintf(tmp, "%s - TGTextEditor", fname);
SetWindowName(tmp);
}
void TGTextEditor::LoadFile(char *fname)
{
char tmp[1024];
TGFileInfo fi;
fi.fFileTypes = ed_filetypes;
if (fname == 0) {
new TGFileDialog(fClient->GetDefaultRoot(), this, kFDOpen, &fi);
if (fi.fFilename && strlen(fi.fFilename)) {
fname = fi.fFilename;
}
}
if (fname) {
if (!fTextEdit->LoadFile(fname)) {
sprintf(tmp, "Error opening file \"%s\"", fname);
new TGMsgBox(fClient->GetRoot(), this, "TGTextEditor",
tmp, kMBIconExclamation, kMBOk);
} else {
fFilename = fname;
sprintf(tmp, "%s: %ld lines read.", fname, fTextEdit->ReturnLineCount());
fStatusBar->SetText(tmp, 0);
sprintf(tmp, "%s - TGTextEditor", fname);
SetWindowName(tmp);
}
}
fTextEdit->Layout();
fTextChanged = kFALSE;
}
void TGTextEditor::SaveFile(const char *fname)
{
char *p, tmp[1024];
if (!fTextEdit->SaveFile(fname)) {
sprintf(tmp, "Error saving file \"%s\"", fname);
new TGMsgBox(fClient->GetRoot(), this, "TGTextEditor",
tmp, kMBIconExclamation, kMBOk);
return;
}
if ((p = (char *)strrchr(fname, '/')) == 0) {
p = (char *)fname;
} else {
++p;
}
sprintf(tmp, "%s: %ld lines written.", p, fTextEdit->ReturnLineCount());
fStatusBar->SetText(tmp, 0);
sprintf(tmp, "%s - TGTextEditor", p);
SetWindowName(tmp);
fTextChanged = kFALSE;
}
Bool_t TGTextEditor::SaveFileAs()
{
static TString dir(".");
static Bool_t overwr = kFALSE;
TGFileInfo fi;
fi.fFileTypes = ed_filetypes;
fi.fIniDir = StrDup(dir);
fi.fOverwrite = overwr;
new TGFileDialog(fClient->GetDefaultRoot(), this, kFDSave, &fi);
overwr = fi.fOverwrite;
if (fi.fFilename && strlen(fi.fFilename)) {
SaveFile(fi.fFilename);
fFilename = fi.fFilename;
return kTRUE;
}
return kFALSE;
}
Int_t TGTextEditor::IsSaved()
{
Int_t ret;
char tmp[1024];
Int_t opt = (kMBYes | kMBNo);
sprintf(tmp, "The text has been modified. Do you want to save the changes?");
if (!fTextChanged) {
return kMBNo;
} else {
if (fParent == gClient->GetDefaultRoot())
opt |= kMBCancel;
new TGMsgBox(fClient->GetRoot(), this, "TGTextEditor",
tmp, kMBIconExclamation, opt, &ret);
return ret;
}
}
void TGTextEditor::PrintText()
{
char tmp[1024];
Int_t ret = 0;
if (!gEPrinter) {
gEPrinter = StrDup("892_2_cor");
gEPrintCommand = StrDup("xprint");
}
new TGPrintDialog(fClient->GetDefaultRoot(), this, 400, 150,
&gEPrinter, &gEPrintCommand, &ret);
if (ret) {
fTextEdit->Print();
sprintf(tmp, "Printed: %s", fFilename.Data());
fStatusBar->SetText(tmp, 0);
}
}
void TGTextEditor::CloseWindow()
{
if (fExiting) {
return;
}
fExiting = kTRUE;
switch (IsSaved()) {
case kMBYes:
if (!fFilename.CompareTo("Untitled"))
SaveFileAs();
else
SaveFile(fFilename.Data());
if ((fTextChanged) && (fParent == gClient->GetDefaultRoot()))
break;
case kMBCancel:
if (fParent == gClient->GetDefaultRoot())
break;
case kMBNo:
TGMainFrame::CloseWindow();
}
fExiting = kFALSE;
}
Bool_t TGTextEditor::HandleKey(Event_t *event)
{
char input[10];
Int_t n;
UInt_t keysym;
if (event->fType == kGKeyPress) {
gVirtualX->LookupString(event, input, sizeof(input), keysym);
n = strlen(input);
switch ((EKeySym)keysym) {
case kKey_Shift:
case kKey_Control:
case kKey_Meta:
case kKey_Alt:
case kKey_CapsLock:
case kKey_NumLock:
case kKey_ScrollLock:
return kTRUE;
case kKey_F1:
SendMessage(this, MK_MSG(kC_COMMAND, kCM_MENU),
kM_HELP_CONTENTS, 0);
return kTRUE;
case kKey_F3:
Search(kTRUE);
return kTRUE;
default:
break;
}
if (event->fState & kKeyControlMask) {
switch((EKeySym)keysym) {
case kKey_F5:
ExecuteMacro();
return kTRUE;
case kKey_F7:
CompileMacro();
return kTRUE;
default:
break;
}
}
if (event->fState & kKeyShiftMask) {
switch((EKeySym)keysym) {
case kKey_F5:
InterruptMacro();
return kTRUE;
default:
break;
}
}
}
return TGMainFrame::HandleKey(event);
}
void TGTextEditor::ClearText()
{
fTextEdit->Clear();
fMacro = 0;
fFilename = "Untitled";
SetWindowName("Untitled - TGTextEditor");
fStatusBar->SetText("New File", 0);
fTextChanged = kFALSE;
}
void TGTextEditor::Search(Bool_t again)
{
if (again) {
SendMessage(fTextEdit, MK_MSG(kC_COMMAND, kCM_MENU),
TGTextEdit::kM_SEARCH_FINDAGAIN, 0);
}
else {
fTextEdit->Search(kFALSE);
}
}
void TGTextEditor::Goto()
{
Long_t ret;
new TGGotoDialog(fClient->GetDefaultRoot(), this, 400, 150, &ret);
if (ret >= 0)
fTextEdit->Goto(ret-1);
}
void TGTextEditor::CompileMacro()
{
if (fTextEdit->ReturnLineCount() < 3)
return;
if ((fMacro) || (!fFilename.CompareTo("Untitled"))) {
if (!SaveFileAs())
return;
}
char *tmpfile = gSystem->ConcatFileName(gSystem->TempDirectory(),
gSystem->BaseName(fFilename.Data()));
fTextEdit->SaveFile(tmpfile, kFALSE);
gSystem->CompileMacro(tmpfile);
gSystem->Unlink(tmpfile);
delete tmpfile;
}
void TGTextEditor::ExecuteMacro()
{
if (fTextEdit->ReturnLineCount() < 3)
return;
if (fMacro) {
fMacro->Exec();
return;
}
if (fTextChanged) {
Int_t ret;
new TGMsgBox(fClient->GetRoot(), this, "TGTextEditor",
"The text has been modified. Do you want to save the changes?",
kMBIconExclamation, kMBYes | kMBNo | kMBCancel, &ret);
if (ret == kMBYes) {
if (!fFilename.CompareTo("Untitled"))
SaveFileAs();
else
SaveFile(fFilename.Data());
fTextChanged = kFALSE;
}
if (ret == kMBCancel)
return;
}
if (!fFilename.CompareTo("Untitled")) {
fFilename += ".C";
}
gInterpreter->SaveContext();
TString savdir = gSystem->WorkingDirectory();
TString tmpfile = gSystem->BaseName(fFilename.Data());
tmpfile += "_exec";
gSystem->ChangeDirectory(gSystem->DirName(fFilename.Data()));
fTextEdit->SaveFile(tmpfile.Data(), kFALSE);
gROOT->SetExecutingMacro(kTRUE);
gROOT->Macro(tmpfile.Data());
gROOT->SetExecutingMacro(kFALSE);
if (gInterpreter->IsLoaded(tmpfile.Data()))
gInterpreter->UnloadFile(tmpfile.Data());
gSystem->Unlink(tmpfile.Data());
gSystem->ChangeDirectory(savdir.Data());
gInterpreter->Reset();
}
void TGTextEditor::InterruptMacro()
{
gROOT->SetInterrupt(kTRUE);
}
void TGTextEditor::About()
{
#ifdef R__UNIX
TString rootx;
# ifdef ROOTBINDIR
rootx = ROOTBINDIR;
# else
rootx = gSystem->Getenv("ROOTSYS");
if (!rootx.IsNull()) rootx += "/bin";
# endif
rootx += "/root -a &";
gSystem->Exec(rootx);
#else
#ifdef WIN32
new TWin32SplashThread(kTRUE);
#else
char str[32];
sprintf(str, "About ROOT %s...", gROOT->GetVersion());
TRootHelpDialog *hd = new TRootHelpDialog(this, str, 600, 400);
hd->SetText(gHelpAbout);
hd->Popup();
#endif
#endif
}
Bool_t TGTextEditor::HandleTimer(TTimer *t)
{
char tmp[1024];
if (t != fTimer) return kTRUE;
if ((gVirtualX->InheritsFrom("TGX11")) &&
(gVirtualX->GetPrimarySelectionOwner() == kNone)) {
fMenuEdit->DisableEntry(kM_EDIT_PASTE);
fToolBar->GetButton(kM_EDIT_PASTE)->SetState(kButtonDisabled);
}
else {
fMenuEdit->EnableEntry(kM_EDIT_PASTE);
if (fToolBar->GetButton(kM_EDIT_PASTE)->GetState() == kButtonDisabled)
fToolBar->GetButton(kM_EDIT_PASTE)->SetState(kButtonUp);
}
if (fTextEdit->IsMarked()) {
fMenuEdit->EnableEntry(kM_EDIT_CUT);
fMenuEdit->EnableEntry(kM_EDIT_COPY);
fMenuEdit->EnableEntry(kM_EDIT_DELETE);
if (fToolBar->GetButton(kM_EDIT_CUT)->GetState() == kButtonDisabled) {
fToolBar->GetButton(kM_EDIT_CUT)->SetState(kButtonUp);
fToolBar->GetButton(kM_EDIT_COPY)->SetState(kButtonUp);
fToolBar->GetButton(kM_EDIT_DELETE)->SetState(kButtonUp);
}
}
else {
fMenuEdit->DisableEntry(kM_EDIT_CUT);
fMenuEdit->DisableEntry(kM_EDIT_COPY);
fMenuEdit->DisableEntry(kM_EDIT_DELETE);
if (fToolBar->GetButton(kM_EDIT_CUT)->GetState() == kButtonUp) {
fToolBar->GetButton(kM_EDIT_CUT)->SetState(kButtonDisabled);
fToolBar->GetButton(kM_EDIT_COPY)->SetState(kButtonDisabled);
fToolBar->GetButton(kM_EDIT_DELETE)->SetState(kButtonDisabled);
}
}
TGLongPosition pos = fTextEdit->GetCurrentPos();
sprintf(tmp, "Ln %ld, Ch %ld", pos.fY, pos.fX);
fStatusBar->SetText(tmp, 1);
fTimer->Reset();
return kTRUE;
}
Bool_t TGTextEditor::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
{
TRootHelpDialog *hd;
switch(GET_MSG(msg)) {
case kC_COMMAND:
switch(GET_SUBMSG(msg)) {
case kCM_BUTTON:
case kCM_MENU:
switch (parm1) {
case kM_FILE_NEW:
new TGTextEditor();
break;
case kM_FILE_OPEN:
switch (IsSaved()) {
case kMBCancel:
break;
case kMBYes:
if (!fFilename.CompareTo("Untitled"))
SaveFileAs();
else
SaveFile(fFilename.Data());
if (fTextChanged)
break;
case kMBNo:
LoadFile();
break;
}
break;
case kM_FILE_SAVE:
if (!fFilename.CompareTo("Untitled"))
SaveFileAs();
else
SaveFile(fFilename.Data());
break;
case kM_FILE_SAVEAS:
SaveFileAs();
break;
case kM_FILE_PRINT:
PrintText();
break;
case kM_FILE_EXIT:
CloseWindow();
break;
case kM_EDIT_CUT:
fTextEdit->Cut();
break;
case kM_EDIT_COPY:
fTextEdit->Copy();
break;
case kM_EDIT_PASTE:
fTextEdit->Paste();
break;
case kM_EDIT_DELETE:
fTextEdit->Delete();
break;
case kM_EDIT_SELECTALL:
fTextEdit->SelectAll();
if (fTextEdit->IsMarked()) {
fMenuEdit->EnableEntry(kM_EDIT_CUT);
fMenuEdit->EnableEntry(kM_EDIT_COPY);
fMenuEdit->EnableEntry(kM_EDIT_DELETE);
if (fToolBar->GetButton(kM_EDIT_CUT)->GetState() == kButtonDisabled) {
fToolBar->GetButton(kM_EDIT_CUT)->SetState(kButtonUp);
fToolBar->GetButton(kM_EDIT_COPY)->SetState(kButtonUp);
fToolBar->GetButton(kM_EDIT_DELETE)->SetState(kButtonUp);
}
}
break;
case kM_EDIT_SELFONT:
{
Int_t count;
char fontname[256];
TGFontDialog::FontProp_t prop;
new TGFontDialog(fClient->GetRoot(), this, &prop);
if (prop.fName != "") {
sprintf(fontname,"-*-%s-%s-%c-*-*-%d-*-*-*-*-*-*-*",
prop.fName.Data(), prop.fBold ? "bold" : "medium",
prop.fItalic ? 'i' : 'r',
prop.fSize);
if (!gVirtualX->ListFonts(fontname, 10, count)) {
sprintf(fontname,"-*-%s-%s-%c-*-*-%d-*-*-*-*-*-*-*",
prop.fName.Data(), prop.fBold ? "bold" : "medium",
prop.fItalic ? 'o' : 'r',
prop.fSize);
}
TGFont *font = fClient->GetFont(fontname);
if (font) {
FontStruct_t editorfont = font->GetFontStruct();
fTextEdit->SetFont(editorfont);
fTextEdit->Update();
}
}
}
break;
case kM_TOOLS_COMPILE:
CompileMacro();
break;
case kM_TOOLS_EXECUTE:
ExecuteMacro();
break;
case kM_TOOLS_INTERRUPT:
InterruptMacro();
break;
case kM_SEARCH_FIND:
Search(kFALSE);
break;
case kM_SEARCH_FINDNEXT:
Search(kTRUE);
break;
case kM_SEARCH_GOTO:
Goto();
break;
case kM_HELP_CONTENTS:
hd = new TRootHelpDialog(this, "Help on Editor...", 600, 400);
hd->SetText(gHelpTextEditor);
hd->Popup();
break;
case kM_HELP_ABOUT:
About();
break;
}
break;
}
break;
case kC_TEXTENTRY:
switch (GET_SUBMSG(msg)) {
case kTE_ENTER:
{
const char *string = fCommandBuf->GetString();
if(strlen(string) > 1) {
gROOT->ProcessLine(string);
fComboCmd->ReturnPressed();
}
}
break;
default:
break;
}
break;
default:
break;
}
return kTRUE;
}