#include "TROOT.h"
#include "TSystem.h"
#include "TApplication.h"
#include "TBrowser.h"
#include "TGClient.h"
#include "TGFrame.h"
#include "TGTab.h"
#include "TGMenu.h"
#include "TGLayout.h"
#include "TGSplitter.h"
#include "TGStatusBar.h"
#include "Varargs.h"
#include "TInterpreter.h"
#include "TBrowser.h"
#include "TGFileDialog.h"
#include "TObjString.h"
#include "TVirtualPad.h"
#include "TEnv.h"
#include <KeySymbols.h>
#include "TRootBrowser.h"
#include "TGFileBrowser.h"
#include "TGInputDialog.h"
#include "TRootHelpDialog.h"
#include "HelpText.h"
#include "Getline.h"
#ifdef WIN32
#include <TWin32SplashThread.h>
#endif
static const char *gOpenFileTypes[] = {
"ROOT files", "*.root",
"All files", "*",
0, 0
};
static const char *gPluginFileTypes[] = {
"ROOT files", "*.C",
"All files", "*",
0, 0
};
enum ENewBrowserMessages {
kBrowse = 11011,
kOpenFile,
kClone,
kHelpAbout,
kHelpOnBrowser,
kHelpOnCanvas,
kHelpOnMenus,
kHelpOnGraphicsEd,
kHelpOnObjects,
kHelpOnPS,
kHelpOnRemote,
kNewEditor,
kNewCanvas,
kNewHtml,
kExecPluginMacro,
kExecPluginCmd,
kCloseTab,
kCloseWindow,
kQuitRoot
};
ClassImp(TRootBrowser)
TRootBrowser::TRootBrowser(TBrowser *b, const char *name, UInt_t width,
UInt_t height, Option_t *opt, Bool_t initshow) :
TGMainFrame(gClient->GetDefaultRoot(), width, height), TBrowserImp(b)
{
fShowCloseTab = kTRUE;
fActBrowser = 0;
CreateBrowser(name);
Resize(width, height);
if (initshow) {
InitPlugins(opt);
MapWindow();
}
gVirtualX->SetInputFocus(GetId());
}
TRootBrowser::TRootBrowser(TBrowser *b, const char *name, Int_t x, Int_t y,
UInt_t width, UInt_t height, Option_t *opt,
Bool_t initshow) :
TGMainFrame(gClient->GetDefaultRoot(), width, height), TBrowserImp(b)
{
fShowCloseTab = kTRUE;
fActBrowser = 0;
CreateBrowser(name);
MoveResize(x, y, width, height);
SetWMPosition(x, y);
if (initshow) {
InitPlugins(opt);
MapWindow();
}
gVirtualX->SetInputFocus(GetId());
}
void TRootBrowser::CreateBrowser(const char *name)
{
fVf = new TGVerticalFrame(this, 100, 100);
fLH0 = new TGLayoutHints(kLHintsNormal);
fLH1 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
fLH2 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 3);
fLH3 = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX);
fLH4 = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX | kLHintsExpandY,2,2,2,2);
fLH5 = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX | kLHintsExpandY);
fLH6 = new TGLayoutHints(kLHintsBottom | kLHintsExpandX);
fLH7 = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandY);
fTopMenuFrame = new TGHorizontalFrame(fVf, 100, 20);
fPreMenuFrame = new TGHorizontalFrame(fTopMenuFrame, 0, 20, kRaisedFrame);
fMenuBar = new TGMenuBar(fPreMenuFrame, 10, 10, kHorizontalFrame);
fMenuFile = new TGPopupMenu(gClient->GetDefaultRoot());
fMenuFile->AddEntry("&Browse... Ctrl+B", kBrowse);
fMenuFile->AddEntry("&Open... Ctrl+O", kOpenFile);
fMenuFile->AddSeparator();
fMenuHelp = new TGPopupMenu(fClient->GetRoot());
fMenuHelp->AddEntry("&About ROOT...", kHelpAbout);
fMenuHelp->AddSeparator();
fMenuHelp->AddEntry("Help On Browser...", kHelpOnBrowser);
fMenuHelp->AddEntry("Help On Canvas...", kHelpOnCanvas);
fMenuHelp->AddEntry("Help On Menus...", kHelpOnMenus);
fMenuHelp->AddEntry("Help On Graphics Editor...", kHelpOnGraphicsEd);
fMenuHelp->AddEntry("Help On Objects...", kHelpOnObjects);
fMenuHelp->AddEntry("Help On PostScript...", kHelpOnPS);
fMenuHelp->AddEntry("Help On Remote Session...", kHelpOnRemote);
fMenuFile->AddPopup("Browser Help...", fMenuHelp);
fMenuFile->AddSeparator();
fMenuFile->AddEntry("&Clone Ctrl+N", kClone);
fMenuFile->AddSeparator();
fMenuFile->AddEntry("New &Editor Ctrl+E", kNewEditor);
fMenuFile->AddEntry("New &Canvas Ctrl+C", kNewCanvas);
fMenuFile->AddEntry("New &HTML Ctrl+H", kNewHtml);
fMenuFile->AddSeparator();
fMenuExecPlugin = new TGPopupMenu(fClient->GetRoot());
fMenuExecPlugin->AddEntry("&Macro...", kExecPluginMacro);
fMenuExecPlugin->AddEntry("&Command...", kExecPluginCmd);
fMenuFile->AddPopup("Execute &Plugin...", fMenuExecPlugin);
fMenuFile->AddSeparator();
fMenuFile->AddEntry("Close &Tab Ctrl+T", kCloseTab);
fMenuFile->AddEntry("Close &Window Ctrl+W", kCloseWindow);
fMenuFile->AddSeparator();
fMenuFile->AddEntry("&Quit Root Ctrl+Q", kQuitRoot);
fMenuBar->AddPopup("&Browser", fMenuFile, fLH1);
fMenuFile->Connect("Activated(Int_t)", "TRootBrowser", this,
"HandleMenu(Int_t)");
fPreMenuFrame->AddFrame(fMenuBar, fLH2);
fTopMenuFrame->AddFrame(fPreMenuFrame, fLH0);
fMenuFrame = new TGHorizontalFrame(fTopMenuFrame, 100, 20, kRaisedFrame);
fTopMenuFrame->AddFrame(fMenuFrame, fLH5);
fVf->AddFrame(fTopMenuFrame, fLH3);
fActMenuBar = fMenuBar;
fToolbarFrame = new TGHorizontalFrame(fVf, 100, 20, kHorizontalFrame |
kRaisedFrame);
fVf->AddFrame(fToolbarFrame, fLH3);
fHf = new TGHorizontalFrame(fVf, 100, 100);
fV1 = new TGVerticalFrame(fHf, 250, 100, kFixedWidth);
fV2 = new TGVerticalFrame(fHf, 600, 100);
fH1 = new TGHorizontalFrame(fV2, 100, 100);
fH2 = new TGHorizontalFrame(fV2, 100, 100, kFixedHeight);
fTabLeft = new TGTab(fV1,100,100);
fTabLeft->Resize(fTabLeft->GetDefaultSize());
fV1->AddFrame(fTabLeft, fLH4);
fVSplitter = new TGVSplitter(fHf, 4, 4);
fVSplitter->SetFrame(fV1, kTRUE);
fHf->AddFrame(fV1, fLH7);
fHf->AddFrame(fVSplitter, fLH7);
fTabRight = new TGTab(fH1, 500, 100);
fTabRight->Resize(fTabRight->GetDefaultSize());
fH1->AddFrame(fTabRight, fLH5);
fTabRight->Connect("Selected(Int_t)", "TRootBrowser", this, "DoTab(Int_t)");
fTabRight->Connect("CloseTab(Int_t)", "TRootBrowser", this, "CloseTab(Int_t)");
fV2->AddFrame(fH1, fLH4);
fHSplitter = new TGHSplitter(fV2, 4, 4);
fV2->AddFrame(fHSplitter, fLH3);
fTabBottom = new TGTab(fH2, 100, 100);
fH2->AddFrame(fTabBottom, fLH4);
fV2->AddFrame(fH2, fLH3);
fHSplitter->SetFrame(fH2, kFALSE);
fHf->AddFrame(fV2, fLH5);
fVf->AddFrame(fHf, fLH5);
AddFrame(fVf, fLH5);
fStatusBar = new TGStatusBar(this, 400, 20);
Int_t parts[] = { 26, 74 };
fStatusBar->SetParts(parts, 2);
AddFrame(fStatusBar, fLH6);
fNbInitPlugins = 0;
fEditFrame = 0;
fEditTab = 0;
fEditPos = -1;
fEditSubPos= -1;
fNbTab[0] = fNbTab[1] = fNbTab[2] = 0;
fCrTab[0] = fCrTab[1] = fCrTab[2] = -1;
SetWindowName(name);
SetIconName(name);
SetClassHints("Browser", "Browser");
if (!strcmp(gROOT->GetDefCanvasName(), "c1"))
gROOT->SetDefCanvasName("Canvas 1");
SetWMSizeHints(600, 350, 10000, 10000, 2, 2);
MapSubwindows();
Resize(GetDefaultSize());
AddInput(kKeyPressMask | kKeyReleaseMask);
fVf->HideFrame(fToolbarFrame);
}
TRootBrowser::~TRootBrowser()
{
delete fLH0;
delete fLH1;
delete fLH2;
delete fLH3;
delete fLH4;
delete fLH5;
delete fLH6;
delete fLH7;
delete fMenuHelp;
delete fMenuExecPlugin;
delete fMenuFile;
delete fMenuBar;
delete fMenuFrame;
delete fPreMenuFrame;
delete fTopMenuFrame;
delete fToolbarFrame;
delete fVSplitter;
delete fHSplitter;
delete fTabLeft;
delete fTabRight;
delete fTabBottom;
delete fH1;
delete fH2;
delete fV1;
delete fV2;
delete fHf;
delete fStatusBar;
delete fVf;
}
void TRootBrowser::Add(TObject *obj, const char *name, Int_t check)
{
if (obj->InheritsFrom("TObjectSpy"))
return;
if (fActBrowser)
fActBrowser->Add(obj, name, check);
}
void TRootBrowser::BrowseObj(TObject *obj)
{
if (fActBrowser)
fActBrowser->BrowseObj(obj);
Emit("BrowseObj(TObject*)", (Long_t)obj);
}
void TRootBrowser::CloneBrowser()
{
Int_t loop = 1;
TBrowserPlugin *plugin = 0;
TBrowser *b = new TBrowser();
TIter next(&fPlugins);
while ((plugin = (TBrowserPlugin *)next())) {
if (loop > fNbInitPlugins)
b->ExecPlugin(plugin->GetName(), "", plugin->fCommand.Data(), plugin->fTab,
plugin->fSubTab);
++loop;
}
}
void TRootBrowser::CloseTab(Int_t id)
{
RemoveTab(kRight, id);
}
void TRootBrowser::CloseWindow()
{
TGFrameElement *el;
Int_t i;
Disconnect(fMenuFile, "Activated(Int_t)", this, "HandleMenu(Int_t)");
Disconnect(fTabRight, "Selected(Int_t)", this, "DoTab(Int_t)");
fActBrowser = 0;
for (i=0;i<fTabLeft->GetNumberOfTabs();i++) {
el = (TGFrameElement *)fTabLeft->GetTabContainer(i)->GetList()->First();
if (el && el->fFrame) {
el->fFrame->SetFrameElement(0);
if (el->fFrame->InheritsFrom("TGMainFrame")) {
((TGMainFrame *)el->fFrame)->CloseWindow();
gSystem->ProcessEvents();
}
else
delete el->fFrame;
el->fFrame = 0;
if (el->fLayout && (el->fLayout != fgDefaultHints) &&
(el->fLayout->References() > 0)) {
el->fLayout->RemoveReference();
if (!el->fLayout->References()) {
delete el->fLayout;
}
}
fTabLeft->GetTabContainer(i)->GetList()->Remove(el);
delete el;
}
}
for (i=0;i<fTabRight->GetNumberOfTabs();i++) {
el = (TGFrameElement *)fTabRight->GetTabContainer(i)->GetList()->First();
if (el && el->fFrame) {
el->fFrame->SetFrameElement(0);
if (el->fFrame->InheritsFrom("TGMainFrame")) {
Bool_t sleep = (el->fFrame->InheritsFrom("TRootCanvas")) ? kTRUE : kFALSE;
((TGMainFrame *)el->fFrame)->CloseWindow();
if (sleep)
gSystem->Sleep(150);
gSystem->ProcessEvents();
}
else
delete el->fFrame;
el->fFrame = 0;
if (el->fLayout && (el->fLayout != fgDefaultHints) &&
(el->fLayout->References() > 0)) {
el->fLayout->RemoveReference();
if (!el->fLayout->References()) {
delete el->fLayout;
}
}
fTabRight->GetTabContainer(i)->GetList()->Remove(el);
delete el;
}
}
for (i=0;i<fTabBottom->GetNumberOfTabs();i++) {
el = (TGFrameElement *)fTabBottom->GetTabContainer(i)->GetList()->First();
if (el && el->fFrame) {
el->fFrame->SetFrameElement(0);
if (el->fFrame->InheritsFrom("TGMainFrame")) {
((TGMainFrame *)el->fFrame)->CloseWindow();
gSystem->ProcessEvents();
}
else
delete el->fFrame;
el->fFrame = 0;
if (el->fLayout && (el->fLayout != fgDefaultHints) &&
(el->fLayout->References() > 0)) {
el->fLayout->RemoveReference();
if (!el->fLayout->References()) {
delete el->fLayout;
}
}
fTabBottom->GetTabContainer(i)->GetList()->Remove(el);
delete el;
}
}
fPlugins.Delete();
Emit("CloseWindow()");
DeleteWindow();
}
void TRootBrowser::DoTab(Int_t id)
{
TGTab *sender = (TGTab *)gTQSender;
if ((sender) && (sender == fTabRight)) {
SwitchMenus(sender->GetTabContainer(id));
}
}
Long_t TRootBrowser::ExecPlugin(const char *name, const char *fname,
const char *cmd, Int_t pos, Int_t subpos)
{
Long_t retval = 0;
TBrowserPlugin *p;
TString command, pname;
StartEmbedding(pos, subpos);
if (cmd && strlen(cmd)) {
command = cmd;
pname = name ? name : Form("Plugin %d", fPlugins.GetSize());
p = new TBrowserPlugin(pname, command.Data(), pos, subpos);
}
else if (fname && strlen(fname)) {
pname = name ? name : gSystem->BaseName(fname);
Ssiz_t t = pname.Last('.');
if (t > 0) pname.Remove(t);
command.Form("gROOT->Macro(\"%s\");", gSystem->UnixPathName(fname));
p = new TBrowserPlugin(pname, command.Data(), pos, subpos);
}
else return 0;
fPlugins.Add(p);
retval = gROOT->ProcessLine(command.Data());
if (command.Contains("new TCanvas")) {
pname = gPad->GetName();
p->SetName(pname.Data());
}
SetTabTitle(pname, pos, subpos);
StopEmbedding();
return retval;
}
Option_t *TRootBrowser::GetDrawOption() const
{
if (fActBrowser)
return fActBrowser->GetDrawOption();
return 0;
}
TGTab* TRootBrowser::GetTab(Int_t pos) const
{
switch (pos) {
case kLeft: return fTabLeft;
case kRight: return fTabRight;
case kBottom: return fTabBottom;
default: return 0;
}
}
Bool_t TRootBrowser::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);
if (!event->fState && (EKeySym)keysym == kKey_F5) {
Refresh(kTRUE);
return kTRUE;
}
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;
default:
break;
}
if (event->fState & kKeyControlMask) {
switch ((EKeySym)keysym & ~0x20) {
case kKey_B:
fMenuFile->Activated(kBrowse);
return kTRUE;
case kKey_O:
fMenuFile->Activated(kOpenFile);
return kTRUE;
case kKey_E:
fMenuFile->Activated(kNewEditor);
return kTRUE;
case kKey_C:
fMenuFile->Activated(kNewCanvas);
return kTRUE;
case kKey_H:
fMenuFile->Activated(kNewHtml);
return kTRUE;
case kKey_N:
fMenuFile->Activated(kClone);
return kTRUE;
case kKey_T:
fMenuFile->Activated(kCloseTab);
return kTRUE;
case kKey_W:
fMenuFile->Activated(kCloseWindow);
return kTRUE;
case kKey_Q:
fMenuFile->Activated(kQuitRoot);
return kTRUE;
default:
break;
}
}
}
return TGMainFrame::HandleKey(event);
}
void TRootBrowser::HandleMenu(Int_t id)
{
TRootHelpDialog *hd;
TString cmd;
static Int_t eNr = 1;
TGPopupMenu *sender = (TGPopupMenu *)gTQSender;
if (sender != fMenuFile)
return;
switch (id) {
case kBrowse:
new TBrowser();
break;
case kOpenFile:
{
static TString dir(".");
TGFileInfo fi;
fi.fFileTypes = gOpenFileTypes;
fi.fIniDir = StrDup(dir);
new TGFileDialog(gClient->GetDefaultRoot(), this,
kFDOpen,&fi);
dir = fi.fIniDir;
if (fi.fMultipleSelection && fi.fFileNamesList) {
TObjString *el;
TIter next(fi.fFileNamesList);
while ((el = (TObjString *) next())) {
gROOT->ProcessLine(Form("new TFile(\"%s\");",
gSystem->UnixPathName(el->GetString())));
}
}
else if (fi.fFilename) {
gROOT->ProcessLine(Form("new TFile(\"%s\");",
gSystem->UnixPathName(fi.fFilename)));
}
}
break;
case kHelpAbout:
{
#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());
hd = new TRootHelpDialog(this, str, 600, 400);
hd->SetText(gHelpAbout);
hd->Popup();
#endif
#endif
}
break;
case kHelpOnCanvas:
hd = new TRootHelpDialog(this, "Help on Canvas...", 600, 400);
hd->SetText(gHelpCanvas);
hd->Popup();
break;
case kHelpOnMenus:
hd = new TRootHelpDialog(this, "Help on Menus...", 600, 400);
hd->SetText(gHelpPullDownMenus);
hd->Popup();
break;
case kHelpOnGraphicsEd:
hd = new TRootHelpDialog(this, "Help on Graphics Editor...", 600, 400);
hd->SetText(gHelpGraphicsEditor);
hd->Popup();
break;
case kHelpOnBrowser:
hd = new TRootHelpDialog(this, "Help on Browser...", 600, 400);
hd->SetText(gHelpBrowser);
hd->Popup();
break;
case kHelpOnObjects:
hd = new TRootHelpDialog(this, "Help on Objects...", 600, 400);
hd->SetText(gHelpObjects);
hd->Popup();
break;
case kHelpOnPS:
hd = new TRootHelpDialog(this, "Help on PostScript...", 600, 400);
hd->SetText(gHelpPostscript);
hd->Popup();
break;
case kHelpOnRemote:
hd = new TRootHelpDialog(this, "Help on Browser...", 600, 400);
hd->SetText(gHelpRemote);
hd->Popup();
break;
case kClone:
CloneBrowser();
break;
case kNewEditor:
cmd.Form("new TGTextEditor((const char *)0, gClient->GetRoot())");
++eNr;
ExecPlugin(Form("Editor %d", eNr), "", cmd.Data(), 1);
break;
case kNewCanvas:
ExecPlugin("", "", "new TCanvas()", 1);
break;
case kNewHtml:
cmd.Form("new TGHtmlBrowser(\"%s\", gClient->GetRoot())",
gEnv->GetValue("Browser.StartUrl", "http://root.cern.ch"));
ExecPlugin("HTML", "", cmd.Data(), 1);
break;
case kExecPluginMacro:
{
static TString dir(".");
TGFileInfo fi;
fi.fFileTypes = gPluginFileTypes;
fi.fIniDir = StrDup(dir);
new TGFileDialog(gClient->GetDefaultRoot(), this,
kFDOpen,&fi);
dir = fi.fIniDir;
if (fi.fFilename) {
ExecPlugin(0, fi.fFilename, 0, kRight);
}
}
break;
case kExecPluginCmd:
{
char command[1024];
strcpy(command, "new TGLSAViewer(gClient->GetRoot(), 0);");
new TGInputDialog(gClient->GetRoot(), this,
"Enter plugin command line:",
command, command);
if (strcmp(command, "")) {
ExecPlugin("User", 0, command, kRight);
}
}
break;
case kCloseTab:
RemoveTab(kRight, fTabRight->GetCurrent());
break;
case kCloseWindow:
CloseWindow();
break;
case kQuitRoot:
gApplication->Terminate(0);
break;
default:
break;
}
}
void TRootBrowser::InitPlugins(Option_t *opt)
{
TString cmd;
if ((opt == 0) || (strlen(opt) == 0))
return;
if (strchr(opt, 'F')) {
cmd.Form("new TGFileBrowser(gClient->GetRoot(), (TBrowser *)0x%lx, 200, 500);", fBrowser);
ExecPlugin("Files", 0, cmd.Data(), 0);
++fNbInitPlugins;
}
if (strchr(opt, 'E')) {
cmd.Form("new TGTextEditor((const char *)0, gClient->GetRoot());");
ExecPlugin("Editor 1", 0, cmd.Data(), 1);
++fNbInitPlugins;
}
if (strchr(opt, 'H')) {
if (gSystem->Load("libGuiHtml") >= 0) {
cmd.Form("new TGHtmlBrowser(\"%s\", gClient->GetRoot());",
gEnv->GetValue("Browser.StartUrl",
"http://root.cern.ch/root/html/ClassIndex.html"));
ExecPlugin("HTML", 0, cmd.Data(), 1);
++fNbInitPlugins;
}
}
if (strchr(opt, 'C')) {
cmd.Form("new TCanvas();");
ExecPlugin("c1", 0, cmd.Data(), 1);
++fNbInitPlugins;
}
if (strchr(opt, 'G')) {
cmd.Form("new TGLSAViewer(gClient->GetRoot(), 0);");
ExecPlugin("OpenGL", 0, cmd.Data(), 1);
++fNbInitPlugins;
}
if (strchr(opt, 'P')) {
cmd.Form("new TSessionViewer();");
ExecPlugin("PROOF", 0, cmd.Data(), 1);
++fNbInitPlugins;
}
if (strchr(opt, 'I')) {
cmd.Form("new TGCommandPlugin(gClient->GetRoot(), 700, 300);");
ExecPlugin("Command", 0, cmd.Data(), 2);
++fNbInitPlugins;
}
SetTab(0, 0);
SetTab(1, 0);
SetTab(2, 0);
}
void TRootBrowser::ReallyDelete()
{
gInterpreter->DeleteGlobal(fBrowser);
delete fBrowser;
}
void TRootBrowser::RecursiveRemove(TObject *obj)
{
if (fActBrowser)
fActBrowser->RecursiveRemove(obj);
}
void TRootBrowser::RecursiveReparent(TGPopupMenu *popup)
{
TGMenuEntry *entry = 0;
TIter next(popup->GetListOfEntries());
while ((entry = (TGMenuEntry *)next())) {
if (entry->GetPopup()) {
RecursiveReparent(entry->GetPopup());
}
}
popup->ReparentWindow(gClient->GetDefaultRoot());
}
void TRootBrowser::Refresh(Bool_t force)
{
if (fActBrowser)
fActBrowser->Refresh(force);
}
void TRootBrowser::RemoveTab(Int_t pos, Int_t subpos)
{
TGTab *edit = 0;
switch (pos) {
case kLeft:
edit = fTabLeft;
break;
case kRight:
edit = fTabRight;
fMenuFrame->HideFrame(fActMenuBar);
fMenuFrame->GetList()->Remove(fActMenuBar);
fActMenuBar = 0;
break;
case kBottom:
edit = fTabBottom;
break;
}
if (!edit->GetTabTab(subpos))
return;
const char *tabName = edit->GetTabTab(subpos)->GetString();
TObject *obj = 0;
if ((obj = fPlugins.FindObject(tabName))) {
fPlugins.Remove(obj);
}
TGFrameElement *el = (TGFrameElement *)edit->GetTabContainer(subpos)->GetList()->First();
if (el && el->fFrame) {
el->fFrame->SetFrameElement(0);
if (el->fFrame->InheritsFrom("TGMainFrame")) {
Bool_t sleep = (el->fFrame->InheritsFrom("TRootCanvas")) ? kTRUE : kFALSE;
((TGMainFrame *)el->fFrame)->CloseWindow();
if (sleep)
gSystem->Sleep(150);
gSystem->ProcessEvents();
}
else
delete el->fFrame;
el->fFrame = 0;
if (el->fLayout && (el->fLayout != fgDefaultHints) &&
(el->fLayout->References() > 0)) {
el->fLayout->RemoveReference();
if (!el->fLayout->References()) {
delete el->fLayout;
}
}
edit->GetTabContainer(subpos)->GetList()->Remove(el);
delete el;
}
fNbTab[pos]--;
edit->RemoveTab(subpos);
SwitchMenus(edit->GetTabContainer(edit->GetCurrent()));
}
void TRootBrowser::SetTab(Int_t pos, Int_t subpos)
{
TGTab *tab = GetTab(pos);
if (subpos == -1)
subpos = fCrTab[pos];
if (tab->SetTab(subpos, kFALSE)) {
if (pos == kRight)
SwitchMenus(tab->GetTabContainer(subpos));
tab->Layout();
}
}
void TRootBrowser::SetTabTitle(const char *title, Int_t pos, Int_t subpos)
{
TBrowserPlugin *p = 0;
TGTab *edit = GetTab(pos);
if (subpos == -1)
subpos = fCrTab[pos];
TGTabElement *el = edit->GetTabTab(subpos);
if (el) {
el->SetText(new TGString(title));
edit->Layout();
if ((p = (TBrowserPlugin *)fPlugins.FindObject(title)))
p->SetName(title);
}
}
void TRootBrowser::SetStatusText(const char* txt, Int_t col)
{
fStatusBar->SetText(txt, col);
}
void TRootBrowser::ShowMenu(TGCompositeFrame *menu)
{
TGFrameElement *el = 0;
fBindList->Delete();
TIter nextm(fMenuBar->GetList());
while ((el = (TGFrameElement *) nextm())) {
TGMenuTitle *t = (TGMenuTitle *) el->fFrame;
Int_t code = t->GetHotKeyCode();
BindKey(fMenuBar, code, kKeyMod1Mask);
BindKey(fMenuBar, code, kKeyMod1Mask | kKeyShiftMask);
BindKey(fMenuBar, code, kKeyMod1Mask | kKeyLockMask);
BindKey(fMenuBar, code, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
BindKey(fMenuBar, code, kKeyMod1Mask | kKeyMod2Mask);
BindKey(fMenuBar, code, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
BindKey(fMenuBar, code, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
BindKey(fMenuBar, code, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
}
fMenuFrame->HideFrame(fActMenuBar);
fMenuFrame->ShowFrame(menu);
menu->Layout();
fMenuFrame->Layout();
fActMenuBar = menu;
}
void TRootBrowser::StartEmbedding(Int_t pos, Int_t subpos)
{
fEditTab = GetTab(pos);
fEditPos = pos;
fEditSubPos = subpos;
if (fEditFrame == 0) {
if (subpos == -1) {
fCrTab[pos] = fNbTab[pos]++;
fEditFrame = fEditTab->AddTab(Form("Tab %d",fNbTab[pos]));
fEditSubPos = fEditTab->GetNumberOfTabs()-1;
fEditFrame->MapWindow();
TGTabElement *tabel = fEditTab->GetTabTab(fEditSubPos);
if(tabel) {
tabel->MapWindow();
if (fShowCloseTab && (pos == 1))
tabel->ShowClose();
}
fEditTab->SetTab(fEditTab->GetNumberOfTabs()-1);
fEditTab->Layout();
}
else {
fCrTab[pos] = subpos;
fEditFrame = fEditTab->GetTabContainer(subpos);
fEditTab->SetTab(subpos);
}
fEditFrame->SetEditable();
}
}
void TRootBrowser::StopEmbedding(const char *name, TGLayoutHints *layout)
{
if (fEditFrame != 0) {
fEditFrame->SetEditable(kFALSE);
if (layout) {
TGFrameElement *el = (TGFrameElement*) fEditFrame->GetList()->Last();
el->fLayout = layout;
}
fEditFrame->Layout();
if (fEditTab == fTabRight)
SwitchMenus(fEditFrame);
}
if (name && strlen(name)) {
SetTabTitle(name, fEditPos, fEditSubPos);
}
fEditFrame = fEditTab = 0;
fEditPos = fEditSubPos = -1;
}
void TRootBrowser::SwitchMenus(TGCompositeFrame *from)
{
if (from == 0)
return;
TGFrameElement *fe = (TGFrameElement *)from->GetList()->First();
if (!fe) {
if (fActMenuBar != fMenuBar)
ShowMenu(fMenuBar);
return;
}
TGCompositeFrame *embed = (TGCompositeFrame *)fe->fFrame;
TGFrameElement *el = 0;
if (embed && embed->GetList()) {
TIter next(embed->GetList());
while ((el = (TGFrameElement *)next())) {
if (el->fFrame->InheritsFrom("TGMenuBar")) {
TGMenuBar *menu = (TGMenuBar *)el->fFrame;
if (fActMenuBar == menu)
return;
TGFrameElement *nw;
TIter nel(fMenuFrame->GetList());
while ((nw = (TGFrameElement *) nel())) {
if (nw->fFrame == menu) {
ShowMenu(menu);
return;
}
}
((TGCompositeFrame *)menu->GetParent())->HideFrame(menu);
menu->ReparentWindow(fMenuFrame);
fMenuFrame->AddFrame(menu, fLH2);
TGFrameElement *mel;
TIter mnext(menu->GetList());
while ((mel = (TGFrameElement *) mnext())) {
TGMenuTitle *t = (TGMenuTitle *) mel->fFrame;
TGPopupMenu *popup = menu->GetPopup(t->GetName());
RecursiveReparent(popup);
if (popup->GetEntry("Close Canvas")) {
TGMenuEntry *exit = popup->GetEntry("Close Canvas");
popup->HideEntry(exit->GetEntryId());
}
if (popup->GetEntry("Close Viewer")) {
TGMenuEntry *exit = popup->GetEntry("Close Viewer");
popup->HideEntry(exit->GetEntryId());
}
if (popup->GetEntry("Quit ROOT")) {
TGMenuEntry *exit = popup->GetEntry("Quit ROOT");
popup->HideEntry(exit->GetEntryId());
}
if (popup->GetEntry("Exit")) {
TGMenuEntry *exit = popup->GetEntry("Exit");
popup->HideEntry(exit->GetEntryId());
}
}
ShowMenu(menu);
return;
}
}
}
if (fActMenuBar != fMenuBar)
ShowMenu(fMenuBar);
}
void TRootBrowser::DoubleClicked(TObject *obj)
{
Emit("DoubleClicked(TObject*)", (Long_t)obj);
}
void TRootBrowser::Checked(TObject *obj, Bool_t checked)
{
Long_t args[2];
args[0] = (Long_t)obj;
args[1] = checked;
Emit("Checked(TObject*,Bool_t)", args);
}
void TRootBrowser::ExecuteDefaultAction(TObject *obj)
{
Emit("ExecuteDefaultAction(TObject*)", (Long_t)obj);
}
TBrowserImp *TRootBrowser::NewBrowser(TBrowser *b, const char *title,
UInt_t width, UInt_t height,
Option_t *opt)
{
TRootBrowser *browser = new TRootBrowser(b, title, width, height, opt);
return (TBrowserImp *)browser;
}
TBrowserImp *TRootBrowser::NewBrowser(TBrowser *b, const char *title, Int_t x,
Int_t y, UInt_t width, UInt_t height,
Option_t *opt)
{
TRootBrowser *browser = new TRootBrowser(b, title, x, y, width, height, opt);
return (TBrowserImp *)browser;
}
Last change: Tue Dec 9 09:00:34 2008
Last generated: 2008-12-09 09:00
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.