00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #include "TROOT.h"
00054 #include "TSystem.h"
00055 #include "TApplication.h"
00056 #include "TBrowser.h"
00057 #include "TGClient.h"
00058 #include "TGFrame.h"
00059 #include "TGTab.h"
00060 #include "TGMenu.h"
00061 #include "TGLayout.h"
00062 #include "TGSplitter.h"
00063 #include "TGStatusBar.h"
00064 #include "Varargs.h"
00065 #include "TInterpreter.h"
00066 #include "TBrowser.h"
00067 #include "TGFileDialog.h"
00068 #include "TObjString.h"
00069 #include "TVirtualPad.h"
00070 #include "TEnv.h"
00071 #include <KeySymbols.h>
00072
00073 #include "TRootBrowser.h"
00074 #include "TGFileBrowser.h"
00075 #include "TGInputDialog.h"
00076 #include "TRootHelpDialog.h"
00077 #include "HelpText.h"
00078
00079 #include "Getline.h"
00080
00081 #ifdef WIN32
00082 #include <TWin32SplashThread.h>
00083 #endif
00084
00085 static const char *gOpenFileTypes[] = {
00086 "ROOT files", "*.root",
00087 "All files", "*",
00088 0, 0
00089 };
00090
00091 static const char *gPluginFileTypes[] = {
00092 "ROOT files", "*.C",
00093 "All files", "*",
00094 0, 0
00095 };
00096
00097 enum ENewBrowserMessages {
00098 kBrowse = 11011,
00099 kOpenFile,
00100 kClone,
00101 kHelpAbout,
00102 kHelpOnBrowser,
00103 kHelpOnCanvas,
00104 kHelpOnMenus,
00105 kHelpOnGraphicsEd,
00106 kHelpOnObjects,
00107 kHelpOnPS,
00108 kHelpOnRemote,
00109 kNewEditor,
00110 kNewCanvas,
00111 kNewHtml,
00112 kExecPluginMacro,
00113 kExecPluginCmd,
00114 kCloseTab,
00115 kCloseWindow,
00116 kQuitRoot
00117 };
00118
00119
00120
00121
00122
00123
00124
00125
00126 ClassImp(TRootBrowser)
00127
00128
00129 TRootBrowser::TRootBrowser(TBrowser *b, const char *name, UInt_t width,
00130 UInt_t height, Option_t *opt, Bool_t initshow) :
00131 TGMainFrame(gClient->GetDefaultRoot(), width, height), TBrowserImp(b)
00132 {
00133
00134
00135 fShowCloseTab = kTRUE;
00136 fActBrowser = 0;
00137 CreateBrowser(name);
00138 Resize(width, height);
00139 if (initshow) {
00140 InitPlugins(opt);
00141 MapWindow();
00142 }
00143 gVirtualX->SetInputFocus(GetId());
00144 }
00145
00146
00147 TRootBrowser::TRootBrowser(TBrowser *b, const char *name, Int_t x, Int_t y,
00148 UInt_t width, UInt_t height, Option_t *opt,
00149 Bool_t initshow) :
00150 TGMainFrame(gClient->GetDefaultRoot(), width, height), TBrowserImp(b)
00151 {
00152
00153
00154 fShowCloseTab = kTRUE;
00155 fActBrowser = 0;
00156 CreateBrowser(name);
00157 MoveResize(x, y, width, height);
00158 SetWMPosition(x, y);
00159 if (initshow) {
00160 InitPlugins(opt);
00161 MapWindow();
00162 }
00163 gVirtualX->SetInputFocus(GetId());
00164 }
00165
00166
00167
00168 void TRootBrowser::CreateBrowser(const char *name)
00169 {
00170
00171
00172
00173 fVf = new TGVerticalFrame(this, 100, 100);
00174
00175 fLH0 = new TGLayoutHints(kLHintsNormal);
00176 fLH1 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
00177 fLH2 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 3);
00178 fLH3 = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX);
00179 fLH4 = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX | kLHintsExpandY,2,2,2,2);
00180 fLH5 = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX | kLHintsExpandY);
00181 fLH6 = new TGLayoutHints(kLHintsBottom | kLHintsExpandX);
00182 fLH7 = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandY);
00183
00184
00185 fTopMenuFrame = new TGHorizontalFrame(fVf, 100, 20);
00186
00187 fPreMenuFrame = new TGHorizontalFrame(fTopMenuFrame, 0, 20, kRaisedFrame);
00188 fMenuBar = new TGMenuBar(fPreMenuFrame, 10, 10, kHorizontalFrame);
00189 fMenuFile = new TGPopupMenu(gClient->GetDefaultRoot());
00190 fMenuFile->AddEntry("&Browse...\tCtrl+B", kBrowse);
00191 fMenuFile->AddEntry("&Open...\tCtrl+O", kOpenFile);
00192 fMenuFile->AddSeparator();
00193
00194 fMenuHelp = new TGPopupMenu(fClient->GetRoot());
00195 fMenuHelp->AddEntry("&About ROOT...", kHelpAbout);
00196 fMenuHelp->AddSeparator();
00197 fMenuHelp->AddEntry("Help On Browser...", kHelpOnBrowser);
00198 fMenuHelp->AddEntry("Help On Canvas...", kHelpOnCanvas);
00199 fMenuHelp->AddEntry("Help On Menus...", kHelpOnMenus);
00200 fMenuHelp->AddEntry("Help On Graphics Editor...", kHelpOnGraphicsEd);
00201 fMenuHelp->AddEntry("Help On Objects...", kHelpOnObjects);
00202 fMenuHelp->AddEntry("Help On PostScript...", kHelpOnPS);
00203 fMenuHelp->AddEntry("Help On Remote Session...", kHelpOnRemote);
00204 fMenuFile->AddPopup("Browser Help...", fMenuHelp);
00205
00206 fMenuFile->AddSeparator();
00207 fMenuFile->AddEntry("&Clone\tCtrl+N", kClone);
00208 fMenuFile->AddSeparator();
00209 fMenuFile->AddEntry("New &Editor\tCtrl+E", kNewEditor);
00210 fMenuFile->AddEntry("New &Canvas\tCtrl+C", kNewCanvas);
00211 fMenuFile->AddEntry("New &HTML\tCtrl+H", kNewHtml);
00212 fMenuFile->AddSeparator();
00213 fMenuExecPlugin = new TGPopupMenu(fClient->GetRoot());
00214 fMenuExecPlugin->AddEntry("&Macro...", kExecPluginMacro);
00215 fMenuExecPlugin->AddEntry("&Command...", kExecPluginCmd);
00216 fMenuFile->AddPopup("Execute &Plugin...", fMenuExecPlugin);
00217 fMenuFile->AddSeparator();
00218 fMenuFile->AddEntry("Close &Tab\tCtrl+T", kCloseTab);
00219 fMenuFile->AddEntry("Close &Window\tCtrl+W", kCloseWindow);
00220 fMenuFile->AddSeparator();
00221 fMenuFile->AddEntry("&Quit Root\tCtrl+Q", kQuitRoot);
00222 fMenuBar->AddPopup("&Browser", fMenuFile, fLH1);
00223 fMenuFile->Connect("Activated(Int_t)", "TRootBrowser", this,
00224 "HandleMenu(Int_t)");
00225 fPreMenuFrame->AddFrame(fMenuBar, fLH2);
00226 fTopMenuFrame->AddFrame(fPreMenuFrame, fLH0);
00227
00228 fMenuFrame = new TGHorizontalFrame(fTopMenuFrame, 100, 20, kRaisedFrame);
00229 fTopMenuFrame->AddFrame(fMenuFrame, fLH5);
00230
00231 fVf->AddFrame(fTopMenuFrame, fLH3);
00232 fActMenuBar = fMenuBar;
00233
00234
00235 fToolbarFrame = new TGHorizontalFrame(fVf, 100, 20, kHorizontalFrame |
00236 kRaisedFrame);
00237 fVf->AddFrame(fToolbarFrame, fLH3);
00238
00239 fHf = new TGHorizontalFrame(fVf, 100, 100);
00240
00241 fV1 = new TGVerticalFrame(fHf, 250, 100, kFixedWidth);
00242 fV2 = new TGVerticalFrame(fHf, 600, 100);
00243 fH1 = new TGHorizontalFrame(fV2, 100, 100);
00244 fH2 = new TGHorizontalFrame(fV2, 100, 100, kFixedHeight);
00245
00246
00247 fTabLeft = new TGTab(fV1,100,100);
00248
00249 fTabLeft->Resize(fTabLeft->GetDefaultSize());
00250 fV1->AddFrame(fTabLeft, fLH4);
00251
00252
00253 fVSplitter = new TGVSplitter(fHf, 4, 4);
00254 fVSplitter->SetFrame(fV1, kTRUE);
00255 fHf->AddFrame(fV1, fLH7);
00256 fHf->AddFrame(fVSplitter, fLH7);
00257
00258
00259 fTabRight = new TGTab(fH1, 500, 100);
00260
00261 fTabRight->Resize(fTabRight->GetDefaultSize());
00262 fH1->AddFrame(fTabRight, fLH5);
00263 fTabRight->Connect("Selected(Int_t)", "TRootBrowser", this, "DoTab(Int_t)");
00264 fTabRight->Connect("CloseTab(Int_t)", "TRootBrowser", this, "CloseTab(Int_t)");
00265 fV2->AddFrame(fH1, fLH4);
00266
00267
00268 fHSplitter = new TGHSplitter(fV2, 4, 4);
00269 fV2->AddFrame(fHSplitter, fLH3);
00270
00271
00272 fTabBottom = new TGTab(fH2, 100, 100);
00273
00274 fH2->AddFrame(fTabBottom, fLH4);
00275 fV2->AddFrame(fH2, fLH3);
00276
00277 fHSplitter->SetFrame(fH2, kFALSE);
00278 fHf->AddFrame(fV2, fLH5);
00279 fVf->AddFrame(fHf, fLH5);
00280 AddFrame(fVf, fLH5);
00281
00282
00283 fStatusBar = new TGStatusBar(this, 400, 20);
00284 Int_t parts[] = { 26, 74 };
00285 fStatusBar->SetParts(parts, 2);
00286 AddFrame(fStatusBar, fLH6);
00287
00288 fNbInitPlugins = 0;
00289 fEditFrame = 0;
00290 fEditTab = 0;
00291 fEditPos = -1;
00292 fEditSubPos= -1;
00293 fNbTab[0] = fNbTab[1] = fNbTab[2] = 0;
00294 fCrTab[0] = fCrTab[1] = fCrTab[2] = -1;
00295
00296
00297 SetWindowName(name);
00298 SetIconName(name);
00299 SetClassHints("Browser", "Browser");
00300
00301 if (!strcmp(gROOT->GetDefCanvasName(), "c1"))
00302 gROOT->SetDefCanvasName("Canvas 1");
00303
00304 SetWMSizeHints(600, 350, 10000, 10000, 2, 2);
00305 MapSubwindows();
00306 Resize(GetDefaultSize());
00307 AddInput(kKeyPressMask | kKeyReleaseMask);
00308
00309 fVf->HideFrame(fToolbarFrame);
00310 }
00311
00312
00313 TRootBrowser::~TRootBrowser()
00314 {
00315
00316
00317 delete fLH0;
00318 delete fLH1;
00319 delete fLH2;
00320 delete fLH3;
00321 delete fLH4;
00322 delete fLH5;
00323 delete fLH6;
00324 delete fLH7;
00325 delete fMenuHelp;
00326 delete fMenuExecPlugin;
00327 delete fMenuFile;
00328 delete fMenuBar;
00329 delete fMenuFrame;
00330 delete fPreMenuFrame;
00331 delete fTopMenuFrame;
00332 delete fToolbarFrame;
00333 delete fVSplitter;
00334 delete fHSplitter;
00335 delete fTabLeft;
00336 delete fTabRight;
00337 delete fTabBottom;
00338 delete fH1;
00339 delete fH2;
00340 delete fV1;
00341 delete fV2;
00342 delete fHf;
00343 delete fStatusBar;
00344 delete fVf;
00345 }
00346
00347
00348 void TRootBrowser::Add(TObject *obj, const char *name, Int_t check)
00349 {
00350
00351
00352
00353
00354
00355 if (obj->InheritsFrom("TObjectSpy"))
00356 return;
00357 if (fActBrowser)
00358 fActBrowser->Add(obj, name, check);
00359 }
00360
00361
00362 void TRootBrowser::BrowseObj(TObject *obj)
00363 {
00364
00365
00366
00367
00368 if (fActBrowser)
00369 fActBrowser->BrowseObj(obj);
00370 Emit("BrowseObj(TObject*)", (Long_t)obj);
00371 }
00372
00373
00374 void TRootBrowser::CloneBrowser()
00375 {
00376
00377
00378
00379 Int_t loop = 1;
00380 TBrowserPlugin *plugin = 0;
00381 TBrowser *b = new TBrowser();
00382 TIter next(&fPlugins);
00383 while ((plugin = (TBrowserPlugin *)next())) {
00384 if (loop > fNbInitPlugins)
00385 b->ExecPlugin(plugin->GetName(), "", plugin->fCommand.Data(), plugin->fTab,
00386 plugin->fSubTab);
00387 ++loop;
00388 }
00389 }
00390
00391
00392 void TRootBrowser::CloseTab(Int_t id)
00393 {
00394
00395
00396 RemoveTab(kRight, id);
00397 }
00398
00399
00400 void TRootBrowser::CloseWindow()
00401 {
00402
00403
00404 TGFrameElement *el;
00405 Int_t i;
00406 Disconnect(fMenuFile, "Activated(Int_t)", this, "HandleMenu(Int_t)");
00407 Disconnect(fTabRight, "Selected(Int_t)", this, "DoTab(Int_t)");
00408 fActBrowser = 0;
00409 for (i=0;i<fTabLeft->GetNumberOfTabs();i++) {
00410 el = (TGFrameElement *)fTabLeft->GetTabContainer(i)->GetList()->First();
00411 if (el && el->fFrame) {
00412 el->fFrame->SetFrameElement(0);
00413 if (el->fFrame->InheritsFrom("TGMainFrame")) {
00414 ((TGMainFrame *)el->fFrame)->CloseWindow();
00415 gSystem->ProcessEvents();
00416 }
00417 else
00418 delete el->fFrame;
00419 el->fFrame = 0;
00420 if (el->fLayout && (el->fLayout != fgDefaultHints) &&
00421 (el->fLayout->References() > 0)) {
00422 el->fLayout->RemoveReference();
00423 if (!el->fLayout->References()) {
00424 delete el->fLayout;
00425 }
00426 }
00427 fTabLeft->GetTabContainer(i)->GetList()->Remove(el);
00428 delete el;
00429 }
00430 }
00431 for (i=0;i<fTabRight->GetNumberOfTabs();i++) {
00432 el = (TGFrameElement *)fTabRight->GetTabContainer(i)->GetList()->First();
00433 if (el && el->fFrame) {
00434 el->fFrame->SetFrameElement(0);
00435 if (el->fFrame->InheritsFrom("TGMainFrame")) {
00436 Bool_t sleep = (el->fFrame->InheritsFrom("TRootCanvas")) ? kTRUE : kFALSE;
00437 ((TGMainFrame *)el->fFrame)->CloseWindow();
00438 if (sleep)
00439 gSystem->Sleep(150);
00440 gSystem->ProcessEvents();
00441 }
00442 else
00443 delete el->fFrame;
00444 el->fFrame = 0;
00445 if (el->fLayout && (el->fLayout != fgDefaultHints) &&
00446 (el->fLayout->References() > 0)) {
00447 el->fLayout->RemoveReference();
00448 if (!el->fLayout->References()) {
00449 delete el->fLayout;
00450 }
00451 }
00452 fTabRight->GetTabContainer(i)->GetList()->Remove(el);
00453 delete el;
00454 }
00455 }
00456 for (i=0;i<fTabBottom->GetNumberOfTabs();i++) {
00457 el = (TGFrameElement *)fTabBottom->GetTabContainer(i)->GetList()->First();
00458 if (el && el->fFrame) {
00459 el->fFrame->SetFrameElement(0);
00460 if (el->fFrame->InheritsFrom("TGMainFrame")) {
00461 ((TGMainFrame *)el->fFrame)->CloseWindow();
00462 gSystem->ProcessEvents();
00463 }
00464 else
00465 delete el->fFrame;
00466 el->fFrame = 0;
00467 if (el->fLayout && (el->fLayout != fgDefaultHints) &&
00468 (el->fLayout->References() > 0)) {
00469 el->fLayout->RemoveReference();
00470 if (!el->fLayout->References()) {
00471 delete el->fLayout;
00472 }
00473 }
00474 fTabBottom->GetTabContainer(i)->GetList()->Remove(el);
00475 delete el;
00476 }
00477 }
00478 fPlugins.Delete();
00479 Emit("CloseWindow()");
00480 DeleteWindow();
00481 }
00482
00483
00484 void TRootBrowser::DoTab(Int_t id)
00485 {
00486
00487
00488 TGTab *sender = (TGTab *)gTQSender;
00489 if ((sender) && (sender == fTabRight)) {
00490 SwitchMenus(sender->GetTabContainer(id));
00491 }
00492 }
00493
00494
00495 Long_t TRootBrowser::ExecPlugin(const char *name, const char *fname,
00496 const char *cmd, Int_t pos, Int_t subpos)
00497 {
00498
00499
00500
00501 Long_t retval = 0;
00502 TBrowserPlugin *p;
00503 TString command, pname;
00504 StartEmbedding(pos, subpos);
00505 if (cmd && strlen(cmd)) {
00506 command = cmd;
00507 if (name) pname = name;
00508 else pname = TString::Format("Plugin %d", fPlugins.GetSize());
00509 p = new TBrowserPlugin(pname.Data(), command.Data(), pos, subpos);
00510 }
00511 else if (fname && strlen(fname)) {
00512 pname = name ? name : gSystem->BaseName(fname);
00513 Ssiz_t t = pname.Last('.');
00514 if (t > 0) pname.Remove(t);
00515 command.Form("gROOT->Macro(\"%s\");", gSystem->UnixPathName(fname));
00516 p = new TBrowserPlugin(pname.Data(), command.Data(), pos, subpos);
00517 }
00518 else return 0;
00519 fPlugins.Add(p);
00520 retval = gROOT->ProcessLine(command.Data());
00521 if (command.Contains("new TCanvas")) {
00522 pname = gPad->GetName();
00523 p->SetName(pname.Data());
00524 }
00525 SetTabTitle(pname.Data(), pos, subpos);
00526 StopEmbedding();
00527 return retval;
00528 }
00529
00530
00531 Option_t *TRootBrowser::GetDrawOption() const
00532 {
00533
00534
00535 if (fActBrowser)
00536 return fActBrowser->GetDrawOption();
00537 return 0;
00538 }
00539
00540
00541 TGTab* TRootBrowser::GetTab(Int_t pos) const
00542 {
00543
00544
00545 switch (pos) {
00546 case kLeft: return fTabLeft;
00547 case kRight: return fTabRight;
00548 case kBottom: return fTabBottom;
00549 default: return 0;
00550 }
00551 }
00552
00553
00554 Bool_t TRootBrowser::HandleKey(Event_t *event)
00555 {
00556
00557
00558 char input[10];
00559 Int_t n;
00560 UInt_t keysym;
00561
00562 if (event->fType == kGKeyPress) {
00563 gVirtualX->LookupString(event, input, sizeof(input), keysym);
00564 n = strlen(input);
00565
00566 if (!event->fState && (EKeySym)keysym == kKey_F5) {
00567 Refresh(kTRUE);
00568 return kTRUE;
00569 }
00570 switch ((EKeySym)keysym) {
00571 case kKey_Shift:
00572 case kKey_Control:
00573 case kKey_Meta:
00574 case kKey_Alt:
00575 case kKey_CapsLock:
00576 case kKey_NumLock:
00577 case kKey_ScrollLock:
00578 return kTRUE;
00579 default:
00580 break;
00581 }
00582 if (event->fState & kKeyControlMask) {
00583 switch ((EKeySym)keysym & ~0x20) {
00584 case kKey_B:
00585 fMenuFile->Activated(kBrowse);
00586 return kTRUE;
00587 case kKey_O:
00588 fMenuFile->Activated(kOpenFile);
00589 return kTRUE;
00590 case kKey_E:
00591 fMenuFile->Activated(kNewEditor);
00592 return kTRUE;
00593 case kKey_C:
00594 fMenuFile->Activated(kNewCanvas);
00595 return kTRUE;
00596 case kKey_H:
00597 fMenuFile->Activated(kNewHtml);
00598 return kTRUE;
00599 case kKey_N:
00600 fMenuFile->Activated(kClone);
00601 return kTRUE;
00602 case kKey_T:
00603 fMenuFile->Activated(kCloseTab);
00604 return kTRUE;
00605 case kKey_W:
00606 fMenuFile->Activated(kCloseWindow);
00607 return kTRUE;
00608 case kKey_Q:
00609 fMenuFile->Activated(kQuitRoot);
00610 return kTRUE;
00611 default:
00612 break;
00613 }
00614 }
00615 }
00616 return TGMainFrame::HandleKey(event);
00617 }
00618
00619
00620 void TRootBrowser::HandleMenu(Int_t id)
00621 {
00622
00623
00624 TRootHelpDialog *hd;
00625 TString cmd;
00626 static Int_t eNr = 1;
00627 TGPopupMenu *sender = (TGPopupMenu *)gTQSender;
00628 if (sender != fMenuFile)
00629 return;
00630 switch (id) {
00631 case kBrowse:
00632 new TBrowser();
00633 break;
00634 case kOpenFile:
00635 {
00636 Bool_t newfile = kFALSE;
00637 static TString dir(".");
00638 TGFileInfo fi;
00639 fi.fFileTypes = gOpenFileTypes;
00640 fi.fIniDir = StrDup(dir);
00641 new TGFileDialog(gClient->GetDefaultRoot(), this,
00642 kFDOpen,&fi);
00643 dir = fi.fIniDir;
00644 if (fi.fMultipleSelection && fi.fFileNamesList) {
00645 TObjString *el;
00646 TIter next(fi.fFileNamesList);
00647 while ((el = (TObjString *) next())) {
00648 gROOT->ProcessLine(Form("new TFile(\"%s\");",
00649 gSystem->UnixPathName(el->GetString())));
00650 }
00651 newfile = kTRUE;
00652 }
00653 else if (fi.fFilename) {
00654 gROOT->ProcessLine(Form("new TFile(\"%s\");",
00655 gSystem->UnixPathName(fi.fFilename)));
00656 newfile = kTRUE;
00657 }
00658 if (fActBrowser && newfile) {
00659 TGFileBrowser *fb = dynamic_cast<TGFileBrowser *>(fActBrowser);
00660 if (fb) fb->Selected(0);
00661 }
00662 }
00663 break;
00664
00665 case kHelpAbout:
00666 {
00667 #ifdef R__UNIX
00668 TString rootx;
00669 # ifdef ROOTBINDIR
00670 rootx = ROOTBINDIR;
00671 # else
00672 rootx = gSystem->Getenv("ROOTSYS");
00673 if (!rootx.IsNull()) rootx += "/bin";
00674 # endif
00675 rootx += "/root -a &";
00676 gSystem->Exec(rootx);
00677 #else
00678 #ifdef WIN32
00679 new TWin32SplashThread(kTRUE);
00680 #else
00681 char str[32];
00682 sprintf(str, "About ROOT %s...", gROOT->GetVersion());
00683 hd = new TRootHelpDialog(this, str, 600, 400);
00684 hd->SetText(gHelpAbout);
00685 hd->Popup();
00686 #endif
00687 #endif
00688 }
00689 break;
00690 case kHelpOnCanvas:
00691 hd = new TRootHelpDialog(this, "Help on Canvas...", 600, 400);
00692 hd->SetText(gHelpCanvas);
00693 hd->Popup();
00694 break;
00695 case kHelpOnMenus:
00696 hd = new TRootHelpDialog(this, "Help on Menus...", 600, 400);
00697 hd->SetText(gHelpPullDownMenus);
00698 hd->Popup();
00699 break;
00700 case kHelpOnGraphicsEd:
00701 hd = new TRootHelpDialog(this, "Help on Graphics Editor...", 600, 400);
00702 hd->SetText(gHelpGraphicsEditor);
00703 hd->Popup();
00704 break;
00705 case kHelpOnBrowser:
00706 hd = new TRootHelpDialog(this, "Help on Browser...", 600, 400);
00707 hd->SetText(gHelpBrowser);
00708 hd->Popup();
00709 break;
00710 case kHelpOnObjects:
00711 hd = new TRootHelpDialog(this, "Help on Objects...", 600, 400);
00712 hd->SetText(gHelpObjects);
00713 hd->Popup();
00714 break;
00715 case kHelpOnPS:
00716 hd = new TRootHelpDialog(this, "Help on PostScript...", 600, 400);
00717 hd->SetText(gHelpPostscript);
00718 hd->Popup();
00719 break;
00720 case kHelpOnRemote:
00721 hd = new TRootHelpDialog(this, "Help on Browser...", 600, 400);
00722 hd->SetText(gHelpRemote);
00723 hd->Popup();
00724 break;
00725 case kClone:
00726 CloneBrowser();
00727 break;
00728 case kNewEditor:
00729 cmd.Form("new TGTextEditor((const char *)0, gClient->GetRoot())");
00730 ++eNr;
00731 ExecPlugin(Form("Editor %d", eNr), "", cmd.Data(), 1);
00732 break;
00733 case kNewCanvas:
00734 ExecPlugin("", "", "new TCanvas()", 1);
00735 break;
00736 case kNewHtml:
00737 cmd.Form("new TGHtmlBrowser(\"%s\", gClient->GetRoot())",
00738 gEnv->GetValue("Browser.StartUrl", "http://root.cern.ch"));
00739 ExecPlugin("HTML", "", cmd.Data(), 1);
00740 break;
00741 case kExecPluginMacro:
00742 {
00743 static TString dir(".");
00744 TGFileInfo fi;
00745 fi.fFileTypes = gPluginFileTypes;
00746 fi.fIniDir = StrDup(dir);
00747 new TGFileDialog(gClient->GetDefaultRoot(), this,
00748 kFDOpen,&fi);
00749 dir = fi.fIniDir;
00750 if (fi.fFilename) {
00751 ExecPlugin(0, fi.fFilename, 0, kRight);
00752 }
00753 }
00754 break;
00755 case kExecPluginCmd:
00756 {
00757 char command[1024];
00758 strlcpy(command, "new TGLSAViewer(gClient->GetRoot(), 0);",
00759 sizeof(command));
00760 new TGInputDialog(gClient->GetRoot(), this,
00761 "Enter plugin command line:",
00762 command, command);
00763 if (strcmp(command, "")) {
00764 ExecPlugin("User", 0, command, kRight);
00765 }
00766 }
00767 break;
00768 case kCloseTab:
00769 RemoveTab(kRight, fTabRight->GetCurrent());
00770 break;
00771 case kCloseWindow:
00772 CloseWindow();
00773 break;
00774 case kQuitRoot:
00775 gApplication->Terminate(0);
00776 break;
00777 default:
00778 break;
00779 }
00780 }
00781
00782
00783 void TRootBrowser::InitPlugins(Option_t *opt)
00784 {
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794 TString cmd;
00795
00796 if ((opt == 0) || (strlen(opt) == 0))
00797 return;
00798
00799
00800
00801 if (strchr(opt, 'F')) {
00802 cmd.Form("new TGFileBrowser(gClient->GetRoot(), (TBrowser *)0x%lx, 200, 500);", (ULong_t)fBrowser);
00803 ExecPlugin("Files", 0, cmd.Data(), 0);
00804 ++fNbInitPlugins;
00805 }
00806
00807
00808
00809 Int_t i, len = strlen(opt);
00810 for (i=0; i<len; ++i) {
00811
00812 if (opt[i] == 'E') {
00813 cmd.Form("new TGTextEditor((const char *)0, gClient->GetRoot());");
00814 ExecPlugin("Editor 1", 0, cmd.Data(), 1);
00815 ++fNbInitPlugins;
00816 }
00817
00818
00819 if (opt[i] == 'H') {
00820 if (gSystem->Load("libGuiHtml") >= 0) {
00821 cmd.Form("new TGHtmlBrowser(\"%s\", gClient->GetRoot());",
00822 gEnv->GetValue("Browser.StartUrl",
00823 "http://root.cern.ch/root/html/ClassIndex.html"));
00824 ExecPlugin("HTML", 0, cmd.Data(), 1);
00825 ++fNbInitPlugins;
00826 }
00827 }
00828
00829
00830 if (opt[i] == 'C') {
00831 cmd.Form("new TCanvas();");
00832 ExecPlugin("c1", 0, cmd.Data(), 1);
00833 ++fNbInitPlugins;
00834 }
00835
00836
00837 if (opt[i] == 'G') {
00838 cmd.Form("new TGLSAViewer(gClient->GetRoot(), 0);");
00839 ExecPlugin("OpenGL", 0, cmd.Data(), 1);
00840 ++fNbInitPlugins;
00841 }
00842
00843
00844 if (opt[i] == 'P') {
00845 cmd.Form("new TSessionViewer();");
00846 ExecPlugin("PROOF", 0, cmd.Data(), 1);
00847 ++fNbInitPlugins;
00848 }
00849 }
00850
00851
00852
00853 if (strchr(opt, 'I')) {
00854 cmd.Form("new TGCommandPlugin(gClient->GetRoot(), 700, 300);");
00855 ExecPlugin("Command", 0, cmd.Data(), 2);
00856 ++fNbInitPlugins;
00857 }
00858
00859
00860 SetTab(0, 0);
00861 SetTab(1, 0);
00862 SetTab(2, 0);
00863 }
00864
00865
00866 void TRootBrowser::ReallyDelete()
00867 {
00868
00869
00870 gInterpreter->DeleteGlobal(fBrowser);
00871 delete fBrowser;
00872 }
00873
00874
00875 void TRootBrowser::RecursiveRemove(TObject *obj)
00876 {
00877
00878
00879 if (fActBrowser)
00880 fActBrowser->RecursiveRemove(obj);
00881 }
00882
00883
00884 void TRootBrowser::RecursiveReparent(TGPopupMenu *popup)
00885 {
00886
00887
00888 TGMenuEntry *entry = 0;
00889 TIter next(popup->GetListOfEntries());
00890 while ((entry = (TGMenuEntry *)next())) {
00891 if (entry->GetPopup()) {
00892 RecursiveReparent(entry->GetPopup());
00893 }
00894 }
00895 popup->ReparentWindow(gClient->GetDefaultRoot());
00896 }
00897
00898
00899 void TRootBrowser::Refresh(Bool_t force)
00900 {
00901
00902
00903 if (fActBrowser)
00904 fActBrowser->Refresh(force);
00905 }
00906
00907
00908 void TRootBrowser::RemoveTab(Int_t pos, Int_t subpos)
00909 {
00910
00911
00912 TGTab *edit = 0;
00913 switch (pos) {
00914 case kLeft:
00915 edit = fTabLeft;
00916 break;
00917 case kRight:
00918 edit = fTabRight;
00919 fMenuFrame->HideFrame(fActMenuBar);
00920 fMenuFrame->GetList()->Remove(fActMenuBar);
00921 fActMenuBar = 0;
00922 break;
00923 case kBottom:
00924 edit = fTabBottom;
00925 break;
00926 }
00927 if (!edit || !edit->GetTabTab(subpos))
00928 return;
00929 const char *tabName = edit->GetTabTab(subpos)->GetString();
00930 TObject *obj = 0;
00931 if ((obj = fPlugins.FindObject(tabName))) {
00932 fPlugins.Remove(obj);
00933 }
00934 TGFrameElement *el = (TGFrameElement *)edit->GetTabContainer(subpos)->GetList()->First();
00935 if (el && el->fFrame) {
00936 el->fFrame->SetFrameElement(0);
00937 if (el->fFrame->InheritsFrom("TGMainFrame")) {
00938 Bool_t sleep = (el->fFrame->InheritsFrom("TRootCanvas")) ? kTRUE : kFALSE;
00939 ((TGMainFrame *)el->fFrame)->CloseWindow();
00940 if (sleep)
00941 gSystem->Sleep(150);
00942 gSystem->ProcessEvents();
00943 }
00944 else
00945 delete el->fFrame;
00946 el->fFrame = 0;
00947 if (el->fLayout && (el->fLayout != fgDefaultHints) &&
00948 (el->fLayout->References() > 0)) {
00949 el->fLayout->RemoveReference();
00950 if (!el->fLayout->References()) {
00951 delete el->fLayout;
00952 }
00953 }
00954 edit->GetTabContainer(subpos)->GetList()->Remove(el);
00955 delete el;
00956 }
00957 fNbTab[pos]--;
00958 edit->RemoveTab(subpos);
00959 SwitchMenus(edit->GetTabContainer(edit->GetCurrent()));
00960 }
00961
00962
00963 void TRootBrowser::SetTab(Int_t pos, Int_t subpos)
00964 {
00965
00966
00967 TGTab *tab = GetTab(pos);
00968 if (subpos == -1)
00969 subpos = fCrTab[pos];
00970
00971 if (tab->SetTab(subpos, kFALSE)) {
00972 if (pos == kRight)
00973 SwitchMenus(tab->GetTabContainer(subpos));
00974 tab->Layout();
00975 }
00976 }
00977
00978
00979 void TRootBrowser::SetTabTitle(const char *title, Int_t pos, Int_t subpos)
00980 {
00981
00982
00983 TBrowserPlugin *p = 0;
00984 TGTab *edit = GetTab(pos);
00985 if (subpos == -1)
00986 subpos = fCrTab[pos];
00987
00988 TGTabElement *el = edit->GetTabTab(subpos);
00989 if (el) {
00990 el->SetText(new TGString(title));
00991 edit->Layout();
00992 if ((p = (TBrowserPlugin *)fPlugins.FindObject(title)))
00993 p->SetName(title);
00994 }
00995 }
00996
00997
00998 void TRootBrowser::SetStatusText(const char* txt, Int_t col)
00999 {
01000
01001
01002 fStatusBar->SetText(txt, col);
01003 }
01004
01005
01006 void TRootBrowser::ShowMenu(TGCompositeFrame *menu)
01007 {
01008
01009
01010 TGFrameElement *el = 0;
01011
01012
01013 fBindList->Delete();
01014 TIter nextm(fMenuBar->GetList());
01015 while ((el = (TGFrameElement *) nextm())) {
01016 TGMenuTitle *t = (TGMenuTitle *) el->fFrame;
01017 Int_t code = t->GetHotKeyCode();
01018 BindKey(fMenuBar, code, kKeyMod1Mask);
01019 BindKey(fMenuBar, code, kKeyMod1Mask | kKeyShiftMask);
01020 BindKey(fMenuBar, code, kKeyMod1Mask | kKeyLockMask);
01021 BindKey(fMenuBar, code, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask);
01022 BindKey(fMenuBar, code, kKeyMod1Mask | kKeyMod2Mask);
01023 BindKey(fMenuBar, code, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask);
01024 BindKey(fMenuBar, code, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask);
01025 BindKey(fMenuBar, code, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask);
01026 }
01027 fMenuFrame->HideFrame(fActMenuBar);
01028 fMenuFrame->ShowFrame(menu);
01029 menu->Layout();
01030 fMenuFrame->Layout();
01031 fActMenuBar = menu;
01032 }
01033
01034
01035 void TRootBrowser::StartEmbedding(Int_t pos, Int_t subpos)
01036 {
01037
01038
01039 fEditTab = GetTab(pos);
01040 fEditPos = pos;
01041 fEditSubPos = subpos;
01042
01043 if (fEditFrame == 0) {
01044 if (subpos == -1) {
01045 fCrTab[pos] = fNbTab[pos]++;
01046 fEditFrame = fEditTab->AddTab(Form("Tab %d",fNbTab[pos]));
01047 fEditSubPos = fEditTab->GetNumberOfTabs()-1;
01048 fEditFrame->MapWindow();
01049 TGTabElement *tabel = fEditTab->GetTabTab(fEditSubPos);
01050 if(tabel) {
01051 tabel->MapWindow();
01052 if (fShowCloseTab && (pos == 1))
01053 tabel->ShowClose();
01054 }
01055 fEditTab->SetTab(fEditTab->GetNumberOfTabs()-1);
01056 fEditTab->Layout();
01057 }
01058 else {
01059 fCrTab[pos] = subpos;
01060 fEditFrame = fEditTab->GetTabContainer(subpos);
01061 fEditTab->SetTab(subpos);
01062 }
01063 fEditFrame->SetEditable();
01064 }
01065 }
01066
01067
01068 void TRootBrowser::StopEmbedding(const char *name, TGLayoutHints *layout)
01069 {
01070
01071
01072 if (fEditFrame != 0) {
01073 fEditFrame->SetEditable(kFALSE);
01074 if (layout) {
01075 TGFrameElement *el = (TGFrameElement*) fEditFrame->GetList()->Last();
01076
01077 el->fLayout = layout;
01078 }
01079 fEditFrame->Layout();
01080 if (fEditTab == fTabRight)
01081 SwitchMenus(fEditFrame);
01082 }
01083 if (name && strlen(name)) {
01084 SetTabTitle(name, fEditPos, fEditSubPos);
01085 }
01086 fEditFrame = fEditTab = 0;
01087 fEditPos = fEditSubPos = -1;
01088 }
01089
01090
01091 void TRootBrowser::SwitchMenus(TGCompositeFrame *from)
01092 {
01093
01094
01095
01096 if (from == 0)
01097 return;
01098 TGFrameElement *fe = (TGFrameElement *)from->GetList()->First();
01099 if (!fe) {
01100 if (fActMenuBar != fMenuBar)
01101 ShowMenu(fMenuBar);
01102 return;
01103 }
01104 TGCompositeFrame *embed = (TGCompositeFrame *)fe->fFrame;
01105 TGFrameElement *el = 0;
01106 if (embed && embed->GetList()) {
01107 TIter next(embed->GetList());
01108 while ((el = (TGFrameElement *)next())) {
01109 if (el->fFrame->InheritsFrom("TGMenuBar")) {
01110 TGMenuBar *menu = (TGMenuBar *)el->fFrame;
01111 if (fActMenuBar == menu)
01112 return;
01113 TGFrameElement *nw;
01114 TIter nel(fMenuFrame->GetList());
01115 while ((nw = (TGFrameElement *) nel())) {
01116 if (nw->fFrame == menu) {
01117 ShowMenu(menu);
01118 return;
01119 }
01120 }
01121 ((TGCompositeFrame *)menu->GetParent())->HideFrame(menu);
01122 menu->ReparentWindow(fMenuFrame);
01123 fMenuFrame->AddFrame(menu, fLH2);
01124 TGFrameElement *mel;
01125 TIter mnext(menu->GetList());
01126 while ((mel = (TGFrameElement *) mnext())) {
01127 TGMenuTitle *t = (TGMenuTitle *) mel->fFrame;
01128 TGPopupMenu *popup = menu->GetPopup(t->GetName());
01129 RecursiveReparent(popup);
01130 if (popup->GetEntry("Close Canvas")) {
01131 TGMenuEntry *exit = popup->GetEntry("Close Canvas");
01132 popup->HideEntry(exit->GetEntryId());
01133 }
01134 if (popup->GetEntry("Close Viewer")) {
01135 TGMenuEntry *exit = popup->GetEntry("Close Viewer");
01136 popup->HideEntry(exit->GetEntryId());
01137 }
01138 if (popup->GetEntry("Quit ROOT")) {
01139 TGMenuEntry *exit = popup->GetEntry("Quit ROOT");
01140 popup->HideEntry(exit->GetEntryId());
01141 }
01142 if (popup->GetEntry("Exit")) {
01143 TGMenuEntry *exit = popup->GetEntry("Exit");
01144 popup->HideEntry(exit->GetEntryId());
01145 }
01146 }
01147 ShowMenu(menu);
01148 return;
01149 }
01150 }
01151 }
01152 if (fActMenuBar != fMenuBar)
01153 ShowMenu(fMenuBar);
01154 }
01155
01156
01157 void TRootBrowser::DoubleClicked(TObject *obj)
01158 {
01159
01160
01161 Emit("DoubleClicked(TObject*)", (Long_t)obj);
01162 }
01163
01164
01165 void TRootBrowser::Checked(TObject *obj, Bool_t checked)
01166 {
01167
01168
01169 Long_t args[2];
01170
01171 args[0] = (Long_t)obj;
01172 args[1] = checked;
01173
01174 Emit("Checked(TObject*,Bool_t)", args);
01175 }
01176
01177
01178 void TRootBrowser::ExecuteDefaultAction(TObject *obj)
01179 {
01180
01181
01182 Emit("ExecuteDefaultAction(TObject*)", (Long_t)obj);
01183 }
01184
01185
01186
01187 TBrowserImp *TRootBrowser::NewBrowser(TBrowser *b, const char *title,
01188 UInt_t width, UInt_t height,
01189 Option_t *opt)
01190 {
01191
01192
01193
01194 TRootBrowser *browser = new TRootBrowser(b, title, width, height, opt);
01195 return (TBrowserImp *)browser;
01196 }
01197
01198
01199 TBrowserImp *TRootBrowser::NewBrowser(TBrowser *b, const char *title, Int_t x,
01200 Int_t y, UInt_t width, UInt_t height,
01201 Option_t *opt)
01202 {
01203
01204
01205
01206 TRootBrowser *browser = new TRootBrowser(b, title, x, y, width, height, opt);
01207 return (TBrowserImp *)browser;
01208 }