]>
Commit | Line | Data |
---|---|---|
32e219c2 | 1 | |
2 | #include "TROOT.h" | |
3 | #include "TSystem.h" | |
4 | #include "TApplication.h" | |
5 | #include "TBrowser.h" | |
6 | #include "TGClient.h" | |
7 | #include "TGFrame.h" | |
8 | #include "TGTab.h" | |
9 | #include "TGMenu.h" | |
10 | #include "TGLayout.h" | |
11 | #include "TGSplitter.h" | |
12 | #include "TGStatusBar.h" | |
13 | #include "Varargs.h" | |
14 | #include "TInterpreter.h" | |
15 | #include "TBrowser.h" | |
16 | #include "TGFileDialog.h" | |
17 | #include "TObjString.h" | |
18 | #include <KeySymbols.h> | |
19 | ||
20 | #include "TGNewBrowser.h" | |
21 | #include "TGFileBrowser.h" | |
22 | ||
23 | #include "Getline.h" | |
24 | ||
25 | #ifdef WIN32 | |
26 | #include <TWin32SplashThread.h> | |
27 | #endif | |
28 | ||
29 | static const char *gOpenFileTypes[] = { | |
30 | "ROOT files", "*.root", | |
31 | "All files", "*", | |
32 | 0, 0 | |
33 | }; | |
34 | ||
35 | static const char *gPluginFileTypes[] = { | |
36 | "ROOT files", "*.C", | |
37 | "All files", "*", | |
38 | 0, 0 | |
39 | }; | |
40 | ||
41 | enum ENewBrowserMessages { | |
42 | kBrowse = 11011, | |
43 | kOpenFile, | |
44 | kNewEditor, | |
45 | kNewCanvas, | |
46 | kExecPlugin, | |
47 | kCloseTab, | |
48 | kCloseWindow, | |
49 | kQuitRoot | |
50 | }; | |
51 | ||
52 | //______________________________________________________________________________ | |
53 | TGNewBrowser::TGNewBrowser(const char *name, UInt_t width, UInt_t height, Bool_t initshow) | |
54 | : TGMainFrame(gClient->GetDefaultRoot(), width, height) | |
55 | { | |
56 | // Create browser with a specified width and height. | |
57 | ||
58 | CreateBrowser(name); | |
59 | Resize(width, height); | |
60 | if (initshow) { | |
61 | InitPlugins(); | |
62 | MapWindow(); | |
63 | } | |
64 | gVirtualX->SetInputFocus(GetId()); | |
65 | } | |
66 | ||
67 | //______________________________________________________________________________ | |
68 | TGNewBrowser::TGNewBrowser(const char *name, Int_t x, Int_t y, | |
69 | UInt_t width, UInt_t height, Bool_t initshow) | |
70 | : TGMainFrame(gClient->GetDefaultRoot(), width, height) | |
71 | { | |
72 | // Create browser with a specified width and height and at position x, y. | |
73 | ||
74 | CreateBrowser(name); | |
75 | MoveResize(x, y, width, height); | |
76 | SetWMPosition(x, y); | |
77 | if (initshow) { | |
78 | InitPlugins(); | |
79 | MapWindow(); | |
80 | } | |
81 | gVirtualX->SetInputFocus(GetId()); | |
82 | } | |
83 | ||
84 | ||
85 | //______________________________________________________________________________ | |
86 | void TGNewBrowser::CreateBrowser(const char *name) | |
87 | { | |
88 | ||
89 | fVf = new TGVerticalFrame(this, 100, 100); | |
90 | ||
91 | fLH0 = new TGLayoutHints(kLHintsNormal); | |
92 | fLH1 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0); | |
93 | fLH2 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 3); | |
94 | fLH3 = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX); | |
95 | fLH4 = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX | kLHintsExpandY,2,2,2,2); | |
96 | fLH5 = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX | kLHintsExpandY); | |
97 | fLH6 = new TGLayoutHints(kLHintsBottom | kLHintsExpandX); | |
98 | fLH7 = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandY); | |
99 | ||
100 | // Menubar Frame | |
101 | fTopMenuFrame = new TGHorizontalFrame(fVf, 100, 20); | |
102 | ||
103 | fPreMenuFrame = new TGHorizontalFrame(fTopMenuFrame, 0, 20, kRaisedFrame); | |
104 | fMenuBar = new TGMenuBar(fPreMenuFrame, 10, 10, kHorizontalFrame); | |
105 | fMenuFile = new TGPopupMenu(gClient->GetDefaultRoot()); | |
106 | fMenuFile->AddEntry("&Browse... Ctrl+B", kBrowse); | |
107 | fMenuFile->AddEntry("&Open... Ctrl+O", kOpenFile); | |
108 | fMenuFile->AddEntry("New &Editor Ctrl+E", kNewEditor); | |
109 | fMenuFile->AddEntry("New &Canvas Ctrl+C", kNewCanvas); | |
110 | fMenuFile->AddEntry("Exec &Plugin... Ctrl+P", kExecPlugin); | |
111 | fMenuFile->AddSeparator(); | |
112 | fMenuFile->AddEntry("Close &Tab Ctrl+T", kCloseTab); | |
113 | fMenuFile->AddEntry("Close &Window Ctrl+W", kCloseWindow); | |
114 | fMenuFile->AddSeparator(); | |
115 | fMenuFile->AddEntry("&Quit Root Ctrl+Q", kQuitRoot); | |
116 | fMenuBar->AddPopup("Framewor&k", fMenuFile, fLH1); | |
117 | fMenuFile->Connect("Activated(Int_t)", "TGNewBrowser", this, | |
118 | "HandleMenu(Int_t)"); | |
119 | fPreMenuFrame->AddFrame(fMenuBar, fLH2); | |
120 | fTopMenuFrame->AddFrame(fPreMenuFrame, fLH0); | |
121 | ||
122 | fMenuFrame = new TGHorizontalFrame(fTopMenuFrame, 100, 20, kRaisedFrame); | |
123 | fTopMenuFrame->AddFrame(fMenuFrame, fLH5); | |
124 | ||
125 | fVf->AddFrame(fTopMenuFrame, fLH3); | |
126 | fActMenuBar = fMenuBar; | |
127 | ||
128 | // Toolbar Frame | |
129 | fToolbarFrame = new TGHorizontalFrame(fVf, 100, 20, kHorizontalFrame | | |
130 | kRaisedFrame); | |
131 | fVf->AddFrame(fToolbarFrame, fLH3); | |
132 | ||
133 | fHf = new TGHorizontalFrame(fVf, 100, 100); | |
134 | // Tabs & co... | |
135 | fV1 = new TGVerticalFrame(fHf, 250, 100, kFixedWidth); | |
136 | fV2 = new TGVerticalFrame(fHf, 600, 100); | |
137 | fH1 = new TGHorizontalFrame(fV2, 100, 100); | |
138 | fH2 = new TGHorizontalFrame(fV2, 100, 100, kFixedHeight); | |
139 | ||
140 | // Left tab | |
141 | fTabLeft = new TGTab(fV1,100,100); | |
142 | //fTabLeft->AddTab("Tab 1"); | |
143 | fTabLeft->Resize(fTabLeft->GetDefaultSize()); | |
144 | fV1->AddFrame(fTabLeft, fLH4); | |
145 | ||
146 | // Vertical splitter | |
147 | fVSplitter = new TGVSplitter(fHf, 4, 4); | |
148 | fVSplitter->SetFrame(fV1, kTRUE); | |
149 | fHf->AddFrame(fV1, fLH7); | |
150 | fHf->AddFrame(fVSplitter, fLH7); | |
151 | ||
152 | // Right tab | |
153 | fTabRight = new TGTab(fH1, 500, 100); | |
154 | //fTabRight->AddTab("Tab 1"); | |
155 | fTabRight->Resize(fTabRight->GetDefaultSize()); | |
156 | fH1->AddFrame(fTabRight, fLH5); | |
157 | fTabRight->Connect("Selected(Int_t)", "TGNewBrowser", this, "DoTab(Int_t)"); | |
158 | fV2->AddFrame(fH1, fLH4); | |
159 | ||
160 | // Horizontal splitter | |
161 | fHSplitter = new TGHSplitter(fV2, 4, 4); | |
162 | fV2->AddFrame(fHSplitter, fLH3); | |
163 | ||
164 | // Bottom tab | |
165 | fTabBottom = new TGTab(fH2, 100, 100); | |
166 | //fTabBottom->AddTab("Tab 1"); | |
167 | fH2->AddFrame(fTabBottom, fLH4); | |
168 | fV2->AddFrame(fH2, fLH3); | |
169 | ||
170 | fHSplitter->SetFrame(fH2, kFALSE); | |
171 | fHf->AddFrame(fV2, fLH5); | |
172 | fVf->AddFrame(fHf, fLH5); | |
173 | AddFrame(fVf, fLH5); | |
174 | ||
175 | // status bar | |
176 | fStatusBar = new TGStatusBar(this, 400, 20); | |
177 | Int_t parts[] = { 80, 20 }; | |
178 | fStatusBar->SetParts(parts, 2); | |
179 | AddFrame(fStatusBar, fLH6); | |
180 | ||
181 | fEditFrame = 0; | |
182 | fEditTab = 0; | |
183 | fNbTab[0] = fNbTab[1] = fNbTab[2] = 0; | |
184 | fCrTab[0] = fCrTab[1] = fCrTab[2] = -1; | |
185 | ||
186 | // Set a name to the main frame | |
187 | SetWindowName(name); | |
188 | SetIconName(name); | |
189 | SetClassHints("Browser", "Browser"); | |
190 | ||
191 | SetWMSizeHints(600, 350, 10000, 10000, 2, 2); | |
192 | MapSubwindows(); | |
193 | Resize(GetDefaultSize()); | |
194 | AddInput(kKeyPressMask | kKeyReleaseMask); | |
195 | ||
196 | fVf->HideFrame(fToolbarFrame); | |
197 | } | |
198 | ||
199 | //______________________________________________________________________________ | |
200 | TGNewBrowser::~TGNewBrowser() | |
201 | { | |
202 | // Clean up all widgets, frames and layouthints that were used | |
203 | ||
204 | delete fLH0; | |
205 | delete fLH1; | |
206 | delete fLH2; | |
207 | delete fLH3; | |
208 | delete fLH4; | |
209 | delete fLH5; | |
210 | delete fLH6; | |
211 | delete fLH7; | |
212 | delete fMenuFile; | |
213 | delete fMenuBar; | |
214 | delete fMenuFrame; | |
215 | delete fToolbarFrame; | |
216 | delete fVSplitter; | |
217 | delete fHSplitter; | |
218 | delete fTabLeft; | |
219 | delete fTabRight; | |
220 | delete fTabBottom; | |
221 | delete fH1; | |
222 | delete fH2; | |
223 | delete fV1; | |
224 | delete fV2; | |
225 | delete fHf; | |
226 | delete fStatusBar; | |
227 | delete fVf; | |
228 | } | |
229 | ||
230 | //______________________________________________________________________________ | |
231 | void TGNewBrowser::CloseWindow() | |
232 | { | |
233 | // Called when window is closed via the window manager. | |
234 | ||
235 | TGFrameElement *el; | |
236 | Int_t i; | |
237 | Disconnect(fMenuFile, "Activated(Int_t)", this, "HandleMenu(Int_t)"); | |
238 | for (i=0;i<fTabLeft->GetNumberOfTabs();i++) { | |
239 | el = (TGFrameElement *)fTabLeft->GetTabContainer(i)->GetList()->First(); | |
240 | if (el && el->fFrame) { | |
241 | el->fFrame->SetFrameElement(0); | |
242 | if (el->fFrame->InheritsFrom("TGMainFrame")) | |
243 | ((TGMainFrame *)el->fFrame)->CloseWindow(); | |
244 | else | |
245 | delete el->fFrame; | |
246 | el->fFrame = 0; | |
247 | if (el->fLayout && (el->fLayout != fgDefaultHints) && | |
248 | (el->fLayout->References() > 0)) { | |
249 | el->fLayout->RemoveReference(); | |
250 | } | |
251 | fTabLeft->GetTabContainer(i)->GetList()->Remove(el); | |
252 | delete el; | |
253 | } | |
254 | } | |
255 | for (i=0;i<fTabRight->GetNumberOfTabs();i++) { | |
256 | el = (TGFrameElement *)fTabRight->GetTabContainer(i)->GetList()->First(); | |
257 | if (el && el->fFrame) { | |
258 | el->fFrame->SetFrameElement(0); | |
259 | if (el->fFrame->InheritsFrom("TGMainFrame")) | |
260 | ((TGMainFrame *)el->fFrame)->CloseWindow(); | |
261 | else | |
262 | delete el->fFrame; | |
263 | el->fFrame = 0; | |
264 | if (el->fLayout && (el->fLayout != fgDefaultHints) && | |
265 | (el->fLayout->References() > 0)) { | |
266 | el->fLayout->RemoveReference(); | |
267 | } | |
268 | fTabRight->GetTabContainer(i)->GetList()->Remove(el); | |
269 | delete el; | |
270 | } | |
271 | } | |
272 | for (i=0;i<fTabBottom->GetNumberOfTabs();i++) { | |
273 | el = (TGFrameElement *)fTabBottom->GetTabContainer(i)->GetList()->First(); | |
274 | if (el && el->fFrame) { | |
275 | el->fFrame->SetFrameElement(0); | |
276 | if (el->fFrame->InheritsFrom("TGMainFrame")) | |
277 | ((TGMainFrame *)el->fFrame)->CloseWindow(); | |
278 | else | |
279 | delete el->fFrame; | |
280 | el->fFrame = 0; | |
281 | if (el->fLayout && (el->fLayout != fgDefaultHints) && | |
282 | (el->fLayout->References() > 0)) { | |
283 | el->fLayout->RemoveReference(); | |
284 | } | |
285 | fTabBottom->GetTabContainer(i)->GetList()->Remove(el); | |
286 | delete el; | |
287 | } | |
288 | } | |
289 | DeleteWindow(); | |
290 | } | |
291 | ||
292 | //______________________________________________________________________________ | |
293 | void TGNewBrowser::DoTab(Int_t id) | |
294 | { | |
295 | // Handle Tab navigation. | |
296 | ||
297 | TGTab *sender = (TGTab *)gTQSender; | |
298 | if ((sender) && (sender == fTabRight)) { | |
299 | SwitchMenus(sender->GetTabContainer(id)); | |
300 | } | |
301 | } | |
302 | ||
303 | //______________________________________________________________________________ | |
304 | void TGNewBrowser::ExecPlugin(const char *fname, Int_t pos, Int_t subpos) | |
305 | { | |
306 | // Execute a macro and embed the created frame in the tab "pos" | |
307 | // and tab element "subpos". | |
308 | ||
309 | StartEmbedding(pos, subpos); | |
310 | gROOT->Macro(fname); | |
311 | StopEmbedding(); | |
312 | } | |
313 | ||
314 | //______________________________________________________________________________ | |
315 | Bool_t TGNewBrowser::HandleKey(Event_t *event) | |
316 | { | |
317 | char input[10]; | |
318 | Int_t n; | |
319 | UInt_t keysym; | |
320 | ||
321 | if (event->fType == kGKeyPress) { | |
322 | gVirtualX->LookupString(event, input, sizeof(input), keysym); | |
323 | n = strlen(input); | |
324 | ||
325 | switch ((EKeySym)keysym) { // ignore these keys | |
326 | case kKey_Shift: | |
327 | case kKey_Control: | |
328 | case kKey_Meta: | |
329 | case kKey_Alt: | |
330 | case kKey_CapsLock: | |
331 | case kKey_NumLock: | |
332 | case kKey_ScrollLock: | |
333 | return kTRUE; | |
334 | default: | |
335 | break; | |
336 | } | |
337 | if (event->fState & kKeyControlMask) { // Cntrl key modifier pressed | |
338 | switch ((EKeySym)keysym & ~0x20) { // treat upper and lower the same | |
339 | case kKey_B: | |
340 | fMenuFile->Activated(kBrowse); | |
341 | return kTRUE; | |
342 | case kKey_O: | |
343 | fMenuFile->Activated(kOpenFile); | |
344 | return kTRUE; | |
345 | case kKey_E: | |
346 | fMenuFile->Activated(kNewEditor); | |
347 | return kTRUE; | |
348 | case kKey_C: | |
349 | fMenuFile->Activated(kNewCanvas); | |
350 | return kTRUE; | |
351 | case kKey_P: | |
352 | fMenuFile->Activated(kExecPlugin); | |
353 | return kTRUE; | |
354 | case kKey_T: | |
355 | fMenuFile->Activated(kCloseTab); | |
356 | return kTRUE; | |
357 | case kKey_W: | |
358 | fMenuFile->Activated(kCloseWindow); | |
359 | return kTRUE; | |
360 | case kKey_Q: | |
361 | fMenuFile->Activated(kQuitRoot); | |
362 | return kTRUE; | |
363 | default: | |
364 | break; | |
365 | } | |
366 | } | |
367 | } | |
368 | return TGMainFrame::HandleKey(event); | |
369 | } | |
370 | ||
371 | //______________________________________________________________________________ | |
372 | void TGNewBrowser::HandleMenu(Int_t id) | |
373 | { | |
374 | // Handle menu items. | |
375 | ||
376 | static Int_t cNr = 1; | |
377 | static Int_t eNr = 1; | |
378 | TGPopupMenu *sender = (TGPopupMenu *)gTQSender; | |
379 | if (sender != fMenuFile) | |
380 | return; | |
381 | switch (id) { | |
382 | case kBrowse: | |
383 | new TBrowser(); | |
384 | break; | |
385 | case kOpenFile: | |
386 | { | |
387 | static TString dir("."); | |
388 | TGFileInfo fi; | |
389 | fi.fFileTypes = gOpenFileTypes; | |
390 | fi.fIniDir = StrDup(dir); | |
391 | new TGFileDialog(gClient->GetDefaultRoot(), this, | |
392 | kFDOpen,&fi); | |
393 | dir = fi.fIniDir; | |
394 | if (fi.fMultipleSelection && fi.fFileNamesList) { | |
395 | TObjString *el; | |
396 | TIter next(fi.fFileNamesList); | |
397 | while ((el = (TObjString *) next())) { | |
398 | gROOT->ProcessLine(Form("new TFile(\"%s\");", | |
399 | gSystem->UnixPathName(el->GetString()))); | |
400 | } | |
401 | } | |
402 | else if (fi.fFilename) { | |
403 | gROOT->ProcessLine(Form("new TFile(\"%s\");", | |
404 | gSystem->UnixPathName(fi.fFilename))); | |
405 | } | |
406 | } | |
407 | break; | |
408 | case kNewEditor: | |
409 | StartEmbedding(1); | |
410 | ++eNr; | |
411 | gROOT->ProcessLine(Form("new TGTextEditor((const char *)0, (const TGWindow *)0x%lx)", | |
412 | gClient->GetRoot())); | |
413 | StopEmbedding(); | |
414 | SetTabTitle(Form("Editor %d", eNr), 1); | |
415 | break; | |
416 | case kNewCanvas: | |
417 | StartEmbedding(1); | |
418 | ++cNr; | |
419 | gROOT->ProcessLine(Form("new TCanvas(\"BrowserCanvas%d\", \"Browser Canvas %d\")", cNr, cNr)); | |
420 | StopEmbedding(); | |
421 | SetTabTitle(Form("Canvas %d", cNr), 1); | |
422 | break; | |
423 | case kExecPlugin: | |
424 | { | |
425 | static TString dir("."); | |
426 | TGFileInfo fi; | |
427 | fi.fFileTypes = gPluginFileTypes; | |
428 | fi.fIniDir = StrDup(dir); | |
429 | new TGFileDialog(gClient->GetDefaultRoot(), this, | |
430 | kFDOpen,&fi); | |
431 | dir = fi.fIniDir; | |
432 | if (fi.fFilename) { | |
433 | ExecPlugin(fi.fFilename, kRight); | |
434 | } | |
435 | } | |
436 | break; | |
437 | case kCloseTab: | |
438 | RemoveFrame(kRight, fTabRight->GetCurrent()); | |
439 | break; | |
440 | case kCloseWindow: | |
441 | CloseWindow(); | |
442 | break; | |
443 | case kQuitRoot: | |
444 | gApplication->Terminate(0); | |
445 | break; | |
446 | default: | |
447 | break; | |
448 | } | |
449 | } | |
450 | ||
451 | //______________________________________________________________________________ | |
452 | void TGNewBrowser::RemoveFrame(Int_t pos, Int_t subpos) | |
453 | { | |
454 | // Remove tab element "subpos" from tab "pos". | |
455 | ||
456 | TGTab *edit = 0; | |
457 | switch (pos) { | |
458 | case kLeft: // left | |
459 | edit = fTabLeft; | |
460 | break; | |
461 | case kRight: // right | |
462 | edit = fTabRight; | |
463 | fMenuFrame->HideFrame(fActMenuBar); | |
464 | fMenuFrame->GetList()->Remove(fActMenuBar); | |
465 | fActMenuBar = 0; | |
466 | break; | |
467 | case kBottom: // bottom | |
468 | edit = fTabBottom; | |
469 | break; | |
470 | } | |
471 | TGFrameElement *el = (TGFrameElement *)edit->GetTabContainer(subpos)->GetList()->First(); | |
472 | if (el && el->fFrame) { | |
473 | el->fFrame->SetFrameElement(0); | |
474 | if (el->fFrame->InheritsFrom("TGMainFrame")) | |
475 | ((TGMainFrame *)el->fFrame)->CloseWindow(); | |
476 | else | |
477 | delete el->fFrame; | |
478 | el->fFrame = 0; | |
479 | if (el->fLayout && (el->fLayout != fgDefaultHints) && | |
480 | (el->fLayout->References() > 0)) { | |
481 | el->fLayout->RemoveReference(); | |
482 | } | |
483 | edit->GetTabContainer(subpos)->GetList()->Remove(el); | |
484 | delete el; | |
485 | } | |
486 | fNbTab[pos]--; | |
487 | edit->RemoveTab(subpos); | |
488 | } | |
489 | ||
490 | //______________________________________________________________________________ | |
491 | TGTab* TGNewBrowser::GetTab(Int_t pos) const | |
492 | { | |
493 | switch (pos) { | |
494 | case kLeft: return fTabLeft; | |
495 | case kRight: return fTabRight; | |
496 | case kBottom: return fTabBottom; | |
497 | default: return 0; | |
498 | } | |
499 | } | |
500 | ||
501 | //______________________________________________________________________________ | |
502 | void TGNewBrowser::SetTab(Int_t pos, Int_t subpos) | |
503 | { | |
504 | TGTab *tab = GetTab(pos); | |
505 | if (subpos == -1) | |
506 | subpos = fCrTab[pos]; | |
507 | ||
508 | if (tab->SetTab(subpos, kFALSE)) { // Block signal emit | |
509 | if (pos == kRight) | |
510 | SwitchMenus(tab->GetTabContainer(subpos)); | |
511 | tab->Layout(); | |
512 | } | |
513 | } | |
514 | ||
515 | //______________________________________________________________________________ | |
516 | void TGNewBrowser::SetTabTitle(const char *title, Int_t pos, Int_t subpos) | |
517 | { | |
518 | TGTab *edit = GetTab(pos); | |
519 | if (subpos == -1) | |
520 | subpos = fCrTab[pos]; | |
521 | ||
522 | TGTabElement *el = edit->GetTabTab(subpos); | |
523 | if (el) { | |
524 | el->SetText(new TGString(title)); | |
525 | edit->Layout(); | |
526 | } | |
527 | } | |
528 | ||
529 | //______________________________________________________________________________ | |
530 | void TGNewBrowser::ShowMenu(TGCompositeFrame *menu) | |
531 | { | |
532 | // Show the selected frame's menu and hide previous one. | |
533 | ||
534 | TGFrameElement *el = 0; | |
535 | // temporary solution until I find a proper way to handle | |
536 | // these bloody menus... | |
537 | fBindList->Delete(); | |
538 | TIter nextm(fMenuBar->GetList()); | |
539 | while ((el = (TGFrameElement *) nextm())) { | |
540 | TGMenuTitle *t = (TGMenuTitle *) el->fFrame; | |
541 | Int_t code = t->GetHotKeyCode(); | |
542 | BindKey(fMenuBar, code, kKeyMod1Mask); | |
543 | BindKey(fMenuBar, code, kKeyMod1Mask | kKeyShiftMask); | |
544 | BindKey(fMenuBar, code, kKeyMod1Mask | kKeyLockMask); | |
545 | BindKey(fMenuBar, code, kKeyMod1Mask | kKeyShiftMask | kKeyLockMask); | |
546 | BindKey(fMenuBar, code, kKeyMod1Mask | kKeyMod2Mask); | |
547 | BindKey(fMenuBar, code, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask); | |
548 | BindKey(fMenuBar, code, kKeyMod1Mask | kKeyMod2Mask | kKeyLockMask); | |
549 | BindKey(fMenuBar, code, kKeyMod1Mask | kKeyShiftMask | kKeyMod2Mask | kKeyLockMask); | |
550 | } | |
551 | fMenuFrame->HideFrame(fActMenuBar); | |
552 | fMenuFrame->ShowFrame(menu); | |
553 | menu->Layout(); | |
554 | fMenuFrame->Layout(); | |
555 | fActMenuBar = menu; | |
556 | } | |
557 | ||
558 | //______________________________________________________________________________ | |
559 | TGCompositeFrame* TGNewBrowser::StartEmbedding(Int_t pos, Int_t subpos) | |
560 | { | |
561 | // Start embedding external frame in the tab "pos" and tab element "subpos". | |
562 | ||
563 | fEditTab = GetTab(pos); | |
564 | ||
565 | if (fEditFrame == 0) { | |
566 | if (subpos == -1) { | |
567 | fCrTab[pos] = fNbTab[pos]++; | |
568 | fEditFrame = fEditTab->AddTab(Form("Tab %d",fNbTab[pos])); | |
569 | fEditFrame->MapWindow(); | |
570 | TGTabElement *tabel = fEditTab->GetTabTab(fEditTab->GetNumberOfTabs()-1); | |
571 | if(tabel) tabel->MapWindow(); | |
572 | fEditTab->SetTab(fEditTab->GetNumberOfTabs()-1); | |
573 | fEditTab->Layout(); | |
574 | } | |
575 | else { | |
576 | fCrTab[pos] = subpos; | |
577 | fEditFrame = fEditTab->GetTabContainer(subpos); | |
578 | fEditTab->SetTab(subpos); | |
579 | } | |
580 | fEditFrame->SetEditable(); | |
581 | } | |
582 | return fEditFrame; | |
583 | } | |
584 | ||
585 | //______________________________________________________________________________ | |
586 | void TGNewBrowser::StopEmbedding(TGLayoutHints *layout) | |
587 | { | |
588 | // Stop embedding external frame in the current editable frame. | |
589 | ||
590 | if (fEditFrame != 0) { | |
591 | fEditFrame->SetEditable(kFALSE); | |
592 | if (layout) { | |
593 | TGFrameElement *el = (TGFrameElement*) fEditFrame->GetList()->Last(); | |
594 | // !!!! MT what to do with the old layout? Leak it for now ... | |
595 | el->fLayout = layout; | |
596 | } | |
597 | fEditFrame->Layout(); | |
598 | if (fEditTab == fTabRight) | |
599 | SwitchMenus(fEditFrame); | |
600 | fEditFrame = fEditTab = 0; | |
601 | } | |
602 | } | |
603 | ||
604 | //______________________________________________________________________________ | |
605 | void TGNewBrowser::SwitchMenus(TGCompositeFrame *from) | |
606 | { | |
607 | // Move the menu from original frame to our TGMenuFrame, or display the | |
608 | // menu associated to the current tab. | |
609 | ||
610 | TGFrameElement *fe = (TGFrameElement *)from->GetList()->First(); | |
611 | if (!fe) { | |
612 | if (fActMenuBar != fMenuBar) | |
613 | ShowMenu(fMenuBar); | |
614 | return; | |
615 | } | |
616 | TGCompositeFrame *embed = (TGCompositeFrame *)fe->fFrame; | |
617 | TGFrameElement *el = 0; | |
618 | if (embed && embed->GetList()) { | |
619 | TIter next(embed->GetList()); | |
620 | while ((el = (TGFrameElement *)next())) { | |
621 | if (el->fFrame->InheritsFrom("TGMenuBar")) { | |
622 | TGMenuBar *menu = (TGMenuBar *)el->fFrame; | |
623 | if (fActMenuBar == menu) | |
624 | return; | |
625 | TGFrameElement *nw; | |
626 | TIter nel(fMenuFrame->GetList()); | |
627 | while ((nw = (TGFrameElement *) nel())) { | |
628 | if (nw->fFrame == menu) { | |
629 | ShowMenu(menu); | |
630 | return; | |
631 | } | |
632 | } | |
633 | ((TGCompositeFrame *)menu->GetParent())->HideFrame(menu); | |
634 | menu->ReparentWindow(fMenuFrame); | |
635 | fMenuFrame->AddFrame(menu, fLH2); | |
636 | TGFrameElement *mel; | |
637 | TIter mnext(menu->GetList()); | |
638 | while ((mel = (TGFrameElement *) mnext())) { | |
639 | TGMenuTitle *t = (TGMenuTitle *) mel->fFrame; | |
640 | TGPopupMenu *popup = menu->GetPopup(t->GetName()); | |
641 | RecursiveReparent(popup); | |
642 | if (popup->GetEntry("Close Canvas")) { | |
643 | TGMenuEntry *exit = popup->GetEntry("Close Canvas"); | |
644 | popup->HideEntry(exit->GetEntryId()); | |
645 | } | |
646 | if (popup->GetEntry("Close Viewer")) { | |
647 | TGMenuEntry *exit = popup->GetEntry("Close Viewer"); | |
648 | popup->HideEntry(exit->GetEntryId()); | |
649 | } | |
650 | if (popup->GetEntry("Quit ROOT")) { | |
651 | TGMenuEntry *exit = popup->GetEntry("Quit ROOT"); | |
652 | popup->HideEntry(exit->GetEntryId()); | |
653 | } | |
654 | if (popup->GetEntry("Exit")) { | |
655 | TGMenuEntry *exit = popup->GetEntry("Exit"); | |
656 | popup->HideEntry(exit->GetEntryId()); | |
657 | } | |
658 | } | |
659 | ShowMenu(menu); | |
660 | return; | |
661 | } | |
662 | } | |
663 | } | |
664 | if (fActMenuBar != fMenuBar) | |
665 | ShowMenu(fMenuBar); | |
666 | } | |
667 | ||
668 | //______________________________________________________________________________ | |
669 | void TGNewBrowser::RecursiveReparent(TGPopupMenu *popup) | |
670 | { | |
671 | TGMenuEntry *entry = 0; | |
672 | TIter next(popup->GetListOfEntries()); | |
673 | while ((entry = (TGMenuEntry *)next())) { | |
674 | if (entry->GetPopup()) { | |
675 | RecursiveReparent(entry->GetPopup()); | |
676 | } | |
677 | } | |
678 | popup->ReparentWindow(gClient->GetDefaultRoot()); | |
679 | } | |
680 | ||
681 | //______________________________________________________________________________ | |
682 | /* | |
683 | void TGNewBrowser::ReallyDelete() | |
684 | { | |
685 | // Really delete the browser and the this GUI. | |
686 | ||
687 | gInterpreter->DeleteGlobal(fBrowser); | |
688 | delete fBrowser; // will in turn delete this object | |
689 | } | |
690 | */ | |
691 | ||
692 | //______________________________________________________________________________ | |
693 | TGFileBrowser* TGNewBrowser::MakeFileBrowser() | |
694 | { | |
695 | // Create a file-browser. Caller should provide | |
696 | // Start/StopEmbedding() calls and populate the new browser. | |
697 | ||
698 | TBrowserImp imp; | |
699 | TBrowser *tb = new TBrowser("Pipi", "Strel", &imp); | |
700 | TGFileBrowser *fb = new TGFileBrowser(tb, "File browser", 200, 500); | |
701 | tb->SetBrowserImp((TBrowserImp *)fb); | |
702 | fb->SetBrowser(tb); | |
703 | fb->SetNewBrowser(this); | |
704 | return fb; | |
705 | } | |
706 | ||
707 | //______________________________________________________________________________ | |
708 | void TGNewBrowser::InitPlugins() | |
709 | { | |
710 | // Initialize default plugins. Could be also of the form: | |
711 | // StartEmbedding(0); | |
712 | // TPluginHandler *ph; | |
713 | // ph = gROOT->GetPluginManager()->FindHandler("TGClassBrowser"); | |
714 | // if (ph && ph->LoadPlugin() != -1) { | |
715 | // ph->ExecPlugin(3, gClient->GetRoot(), 200, 500); | |
716 | // } | |
717 | // StopEmbedding(); | |
718 | ||
719 | // --- Left vertical area | |
720 | ||
721 | // File browser plugin... | |
722 | StartEmbedding(0); | |
723 | //gROOT->ProcessLine(Form("new TGFileBrowser((const TGWindow *)0x%lx, 200, 500)", | |
724 | // gClient->GetRoot())); | |
725 | { | |
726 | TGFileBrowser *fb = MakeFileBrowser(); | |
727 | fb->BrowseObj(gROOT); | |
728 | fb->AddFSDirectory("/"); | |
729 | fb->GotoDir(gSystem->WorkingDirectory()); | |
730 | fb->Show(); | |
731 | } | |
732 | StopEmbedding(); | |
733 | SetTabTitle("Files", 0); | |
734 | ||
735 | // Class browser plugin | |
736 | StartEmbedding(0); | |
737 | gROOT->ProcessLine(Form("new TGClassBrowser((const TGWindow *)0x%lx, 200, 500)", | |
738 | gClient->GetRoot())); | |
739 | StopEmbedding(); | |
740 | SetTabTitle("Classes", 0); | |
741 | ||
742 | // --- Right main area | |
743 | ||
744 | // Editor plugin... | |
745 | StartEmbedding(1); | |
746 | gROOT->ProcessLine(Form("new TGTextEditor((const char *)0, (const TGWindow *)0x%lx)", | |
747 | gClient->GetRoot())); | |
748 | StopEmbedding(); | |
749 | SetTabTitle("Editor 1", 1); | |
750 | ||
751 | // HTML plugin... | |
752 | gSystem->Load("libGuiHtml"); | |
753 | if (gSystem->Load("libRHtml") >= 0) { | |
754 | StartEmbedding(1); | |
755 | gROOT->ProcessLine(Form("new TGHtmlBrowser(\"http://root.cern.ch/root/html/ClassIndex.html\", \ | |
756 | (const TGWindow *)0x%lx)", gClient->GetRoot())); | |
757 | StopEmbedding(); | |
758 | SetTabTitle("HTML", 1); | |
759 | } | |
760 | ||
761 | // Canvas plugin... | |
762 | StartEmbedding(1); | |
763 | gROOT->ProcessLine("new TCanvas(\"BrowserCanvas1\", \"Browser Canvas 1\")"); | |
764 | StopEmbedding(); | |
765 | SetTabTitle("Canvas 1", 1); | |
766 | ||
767 | #if 0 | |
768 | // GLViewer plugin... | |
769 | StartEmbedding(1); | |
770 | gROOT->ProcessLine(Form("new TGLSAViewer((TGFrame *)0x%lx, 0);", gClient->GetRoot())); | |
771 | StopEmbedding(); | |
772 | SetTabTitle("GL Viewer", 1); | |
773 | ||
774 | // PROOF plugin... | |
775 | StartEmbedding(1); | |
776 | gROOT->ProcessLine("new TSessionViewer();"); | |
777 | StopEmbedding(); | |
778 | SetTabTitle("PROOF", 1); | |
779 | #endif | |
780 | ||
781 | // --- Right bottom area | |
782 | ||
783 | // Command plugin... | |
784 | StartEmbedding(2); | |
785 | gROOT->ProcessLine(Form("new TGCommandPlugin((const TGWindow *)0x%lx, 700, 300)", | |
786 | gClient->GetRoot())); | |
787 | StopEmbedding(); | |
788 | SetTabTitle("Command", 2); | |
789 | ||
790 | // --- Select first tab everywhere | |
791 | SetTab(0, 0); | |
792 | SetTab(1, 0); | |
793 | SetTab(2, 0); | |
794 | } | |
795 | ||
796 | /* | |
797 | //______________________________________________________________________________ | |
798 | TBrowserImp *TGNewBrowser::NewBrowser(TBrowser *b, const char *title, UInt_t width, UInt_t height) | |
799 | { | |
800 | TGNewBrowser *browser = new TGNewBrowser(b, title, width, height); | |
801 | return (TBrowserImp *)browser; | |
802 | } | |
803 | ||
804 | //______________________________________________________________________________ | |
805 | TBrowserImp *TGNewBrowser::NewBrowser(TBrowser *b, const char *title, Int_t x, Int_t y, UInt_t width, UInt_t height) | |
806 | { | |
807 | TGNewBrowser *browser = new TGNewBrowser(b, title, x, y, width, height); | |
808 | return (TBrowserImp *)browser; | |
809 | } | |
810 | */ |