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
00054
00055
00056
00057 #include "TGedEditor.h"
00058 #include "TCanvas.h"
00059 #include "TGCanvas.h"
00060 #include "TGTab.h"
00061 #include "TGedFrame.h"
00062 #include "TGLabel.h"
00063 #include "TROOT.h"
00064 #include "TClass.h"
00065 #include "TBaseClass.h"
00066
00067 class TGedTabInfo : public TObject {
00068
00069 public:
00070 TGTabElement *fElement;
00071 TGCompositeFrame *fContainer;
00072
00073 TGedTabInfo(TGTabElement* el, TGCompositeFrame* f) :
00074 fElement(el), fContainer(f) {}
00075 };
00076
00077
00078 ClassImp(TGedEditor)
00079
00080 TGedEditor* TGedEditor::fgFrameCreator = 0;
00081
00082
00083 TGedEditor* TGedEditor::GetFrameCreator()
00084 {
00085
00086
00087 return fgFrameCreator;
00088 }
00089
00090
00091 void TGedEditor::SetFrameCreator(TGedEditor* e)
00092 {
00093
00094
00095 fgFrameCreator = e;
00096 }
00097
00098
00099 TGedEditor::TGedEditor(TCanvas* canvas, UInt_t width, UInt_t height) :
00100 TGMainFrame(gClient->GetRoot(), width, height),
00101 fCan (0),
00102 fTab (0),
00103 fTabContainer (0),
00104 fModel (0),
00105 fPad (0),
00106 fCanvas (0),
00107 fClass (0),
00108 fGlobal (kTRUE)
00109 {
00110
00111
00112 fCan = new TGCanvas(this, 170, 10, kFixedWidth);
00113 AddFrame(fCan, new TGLayoutHints(kLHintsExpandY | kLHintsExpandX));
00114
00115 fTab = new TGTab(fCan->GetViewPort(), 10, 10);
00116 fTab->Associate(fCan);
00117 fTab->SetCleanup(kDeepCleanup);
00118 fCan->SetContainer(fTab);
00119
00120 fTabContainer = GetEditorTab("Style");
00121
00122 gROOT->GetListOfCleanups()->Add(this);
00123
00124 SetCanvas(canvas);
00125 if (fCanvas) {
00126 UInt_t ch = fCanvas->GetWindowHeight();
00127 if (ch)
00128 Resize(GetWidth(), ch > 700 ? 700 : ch);
00129 else
00130 Resize(GetWidth(), fCanvas->GetWh()<450 ? 450 : fCanvas->GetWh() + 4);
00131 } else {
00132 Resize(width, height);
00133 }
00134
00135 MapSubwindows();
00136 MapWindow();
00137 }
00138
00139
00140 TGedEditor::~TGedEditor()
00141 {
00142
00143
00144 Hide();
00145
00146 if(fGlobal){
00147 TQObject::Disconnect("TCanvas", "Selected(TVirtualPad *, TObject *, Int_t)");
00148 TQObject::Disconnect("TCanvas", "Closed()");
00149 }
00150
00151
00152 TIter next(fFrameMap.GetTable());
00153 TPair* pair;
00154 while ((pair = (TPair*) next())) {
00155 if (pair->Value() != 0) {
00156 TGedFrame* frame = (TGedFrame*) pair->Value();
00157 delete frame;
00158 }
00159 }
00160
00161 TGedTabInfo* ti;
00162 TIter it1(&fCreatedTabs);
00163 while ((ti = (TGedTabInfo*) it1())) {
00164 fTab->AddFrame(ti->fElement,0);
00165 fTab->AddFrame(ti->fContainer,0);
00166 }
00167
00168 delete fTab;
00169 delete ((TGFrameElement*)fList->First())->fLayout;
00170 delete fCan;
00171 }
00172
00173
00174 void TGedEditor::Update(TGedFrame* )
00175 {
00176
00177
00178
00179 if (fPad) {
00180 fPad->Modified();
00181 fPad->Update();
00182 }
00183 }
00184
00185
00186 TGCompositeFrame* TGedEditor::GetEditorTab(const char* name)
00187 {
00188
00189
00190 return GetEditorTabInfo(name)->fContainer;
00191 }
00192
00193
00194 TGedTabInfo* TGedEditor::GetEditorTabInfo(const char* name)
00195 {
00196
00197
00198
00199 if ( ! fCreatedTabs.IsEmpty()) {
00200 TIter next(&fCreatedTabs);
00201 TGedTabInfo* ti;
00202 while ((ti = (TGedTabInfo *) next())) {
00203 if (*ti->fElement->GetText() == name)
00204 return ti;
00205 }
00206 }
00207
00208
00209 TGCompositeFrame* tc = fTab->AddTab(new TGString(name));
00210
00211
00212 TGTabElement *te = fTab->GetTabTab(fTab->GetNumberOfTabs() - 1);
00213 fTab->RemoveFrame(tc);
00214 fTab->RemoveFrame(te);
00215
00216
00217 TGedFrame* nf = CreateNameFrame(tc, name);
00218 nf->SetGedEditor(this);
00219 nf->SetModelClass(0);
00220 tc->AddFrame(nf, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 2));
00221
00222
00223 TGedTabInfo* ti = new TGedTabInfo(te, tc);
00224 fCreatedTabs.Add(ti);
00225
00226 return ti;
00227 }
00228
00229
00230 void TGedEditor::CloseWindow()
00231 {
00232
00233
00234 Hide();
00235 }
00236
00237
00238 void TGedEditor::ReinitWorkspace()
00239 {
00240
00241
00242
00243
00244 TIter next(&fVisibleTabs);
00245 TGedTabInfo* ti;
00246 while ((ti = (TGedTabInfo*)next())) {
00247 TGTabElement *te = ti->fElement;
00248 TGCompositeFrame *tc = ti->fContainer;
00249
00250 fTab->RemoveFrame(te);
00251 fTab->RemoveFrame(tc);
00252
00253 TIter frames(tc->GetList());
00254 frames();
00255 TGFrameElement* fr;
00256 while ((fr = (TGFrameElement *) frames()) != 0) {
00257 TGFrame *f = fr->fFrame;
00258 tc->RemoveFrame(f);
00259 f->UnmapWindow();
00260 te->UnmapWindow();
00261 tc->UnmapWindow();
00262 }
00263 fVisibleTabs.Remove(ti);
00264 }
00265 }
00266
00267
00268 void TGedEditor::SetGlobal(Bool_t global)
00269 {
00270
00271
00272 fGlobal = global;
00273 if (fGlobal) {
00274 TQObject::Connect("TCanvas", "Selected(TVirtualPad *, TObject *, Int_t)",
00275 "TGedEditor", this, "GlobalSetModel(TVirtualPad *, TObject *, Int_t)");
00276
00277 TQObject::Connect("TCanvas", "Closed()",
00278 "TGedEditor", this, "GlobalClosed()");
00279 }
00280 }
00281
00282
00283 void TGedEditor::GlobalClosed()
00284 {
00285
00286
00287 if (gROOT->GetListOfCanvases()->IsEmpty())
00288 TVirtualPadEditor::Terminate();
00289 }
00290
00291
00292 void TGedEditor::GlobalSetModel(TVirtualPad *pad, TObject * obj, Int_t ev)
00293 {
00294
00295
00296 if ((ev != kButton1Down) || !IsMapped() ||
00297 (obj && obj->InheritsFrom("TColorWheel")))
00298 return;
00299
00300 TCanvas* can = pad->GetCanvas();
00301
00302
00303 if (can == fCanvas || can->GetShowEditor())
00304 return;
00305
00306 Show();
00307 }
00308
00309
00310 void TGedEditor::ConnectToCanvas(TCanvas *c)
00311 {
00312
00313
00314 c->Connect("Selected(TVirtualPad*,TObject*,Int_t)", "TGedEditor",
00315 this, "SetModel(TVirtualPad*,TObject*,Int_t)");
00316 }
00317
00318
00319 void TGedEditor::DisconnectFromCanvas()
00320 {
00321
00322
00323 if (fCanvas)
00324 Disconnect(fCanvas, "Selected(TVirtualPad*,TObject*,Int_t)", this, "SetModel(TVirtualPad*,TObject*,Int_t)");
00325 }
00326
00327
00328 void TGedEditor::SetCanvas(TCanvas *newcan)
00329 {
00330
00331
00332 if (!newcan || (fCanvas == newcan)) return;
00333
00334 DisconnectFromCanvas();
00335 fCanvas = newcan;
00336
00337 SetWindowName(Form("%s_Editor", fCanvas->GetName()));
00338 fPad = fCanvas->GetSelectedPad();
00339 if (fPad == 0) fPad = fCanvas;
00340 ConnectToCanvas(fCanvas);
00341 }
00342
00343
00344 void TGedEditor::SetModel(TVirtualPad* pad, TObject* obj, Int_t event)
00345 {
00346
00347
00348 if ((event != kButton1Down) || (obj && obj->InheritsFrom("TColorWheel")))
00349 return;
00350
00351 if (gPad) gPad->GetVirtCanvas()->SetCursor(kWatch);
00352 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kWatch));
00353
00354 fPad = pad;
00355 if (obj == 0) obj = fPad;
00356
00357
00358 TGTabElement* seltab = fTab->GetCurrentTab();
00359
00360 Bool_t mapTabs = kFALSE;
00361 if (fModel != obj) {
00362 fModel = obj;
00363 if (fModel == 0 || fModel->IsA() != fClass) {
00364 ReinitWorkspace();
00365 mapTabs = kTRUE;
00366
00367 fVisibleTabs.Add(fCreatedTabs.First());
00368 if (fModel) {
00369 fClass = fModel->IsA();
00370
00371 ActivateEditor(fClass, kTRUE);
00372 } else {
00373 fClass = 0;
00374 }
00375
00376
00377 TGedFrame* gfr;
00378 TIter ngf(&fGedFrames);
00379 while ((gfr = (TGedFrame*) ngf()))
00380 fTabContainer->AddFrame(gfr, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 2));
00381
00382 fExclMap.Clear();
00383 fGedFrames.Clear();
00384
00385
00386 TIter next(&fVisibleTabs);
00387 TGedTabInfo* ti;
00388 while ((ti = (TGedTabInfo *) next())) {
00389 fTab->AddFrame(ti->fElement,0);
00390 fTab->AddFrame(ti->fContainer,0);
00391 }
00392 }
00393 ConfigureGedFrames(kTRUE);
00394 } else {
00395 ConfigureGedFrames(kFALSE);
00396 }
00397
00398 if (mapTabs) {
00399 TGedTabInfo* ti;
00400 TIter next(&fVisibleTabs);
00401 while ((ti = (TGedTabInfo *) next())) {
00402 ti->fElement->MapWindow();
00403 ti->fContainer->MapWindow();
00404 }
00405 if (seltab == 0 || fTab->SetTab(seltab->GetString(), kFALSE) == kFALSE)
00406 fTab->SetTab(0, kFALSE);
00407 }
00408
00409 if (fGlobal)
00410 Layout();
00411 else
00412 ((TGMainFrame*)GetMainFrame())->Layout();
00413
00414 if (gPad) gPad->GetVirtCanvas()->SetCursor(kPointer);
00415 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
00416 }
00417
00418
00419 void TGedEditor::Show()
00420 {
00421
00422
00423
00424 if (gPad) SetCanvas(gPad->GetCanvas());
00425
00426 if (fCanvas && fGlobal) {
00427 SetModel(fCanvas->GetClickSelectedPad(), fCanvas->GetClickSelected(), kButton1Down);
00428
00429 if (fCanvas->GetShowEditor())
00430 fCanvas->ToggleEditor();
00431
00432 UInt_t dw = fClient->GetDisplayWidth();
00433 UInt_t cw = fCanvas->GetWindowWidth();
00434 UInt_t ch = fCanvas->GetWindowHeight();
00435 UInt_t cx = (UInt_t)fCanvas->GetWindowTopX();
00436 UInt_t cy = (UInt_t)fCanvas->GetWindowTopY();
00437 if (!ch)
00438 cy = cy + 20;
00439
00440 Int_t gedx = 0, gedy = 0;
00441
00442 if (cw + GetWidth() > dw) {
00443 gedx = cx + cw - GetWidth();
00444 gedy = ch - GetHeight();
00445 } else {
00446 if (cx > GetWidth())
00447 gedx = cx - GetWidth() - 20;
00448 else
00449 gedx = cx + cw + 10;
00450 gedy = cy - 20;
00451 }
00452 MoveResize(gedx, gedy, GetWidth(), ch > 700 ? 700 : ch);
00453 SetWMPosition(gedx, gedy);
00454 } else if (fCanvas) {
00455 SetModel(fCanvas, fCanvas, kButton1Down);
00456 }
00457 MapWindow();
00458 gVirtualX->RaiseWindow(GetId());
00459
00460 if (!gROOT->GetListOfCleanups()->FindObject(this))
00461 gROOT->GetListOfCleanups()->Add(this);
00462 }
00463
00464
00465 void TGedEditor::Hide()
00466 {
00467
00468
00469 UnmapWindow();
00470 ReinitWorkspace();
00471 fModel = 0; fClass = 0;
00472 DisconnectFromCanvas();
00473 fCanvas = 0; fPad = 0;
00474 gROOT->GetListOfCleanups()->Remove(this);
00475 }
00476
00477
00478 void TGedEditor::RecursiveRemove(TObject* obj)
00479 {
00480
00481
00482
00483 if (obj == fPad) {
00484
00485 SetModel(fCanvas, fCanvas, kButton1Down);
00486 return;
00487 }
00488
00489 if (obj == fModel) {
00490
00491 SetModel(fPad, fPad, kButton1Down);
00492 return;
00493 }
00494 }
00495
00496
00497 void TGedEditor::ActivateEditor(TClass* cl, Bool_t recurse)
00498 {
00499
00500
00501
00502 TPair *pair = (TPair*) fFrameMap.FindObject(cl);
00503 TClass *edClass = 0;
00504 TGedFrame *frame = 0;
00505
00506 if (pair == 0) {
00507 edClass = TClass::GetClass(Form("%sEditor", cl->GetName()));
00508
00509 if (edClass && edClass->InheritsFrom(TGedFrame::Class())) {
00510 TGWindow *exroot = (TGWindow*) fClient->GetRoot();
00511 fClient->SetRoot(fTabContainer);
00512 fgFrameCreator = this;
00513 frame = reinterpret_cast<TGedFrame*>(edClass->New());
00514 frame->SetModelClass(cl);
00515 fgFrameCreator = 0;
00516 fClient->SetRoot(exroot);
00517 }
00518 fFrameMap.Add(cl, frame);
00519 } else {
00520 frame = (TGedFrame*)pair->Value();
00521 }
00522
00523 Bool_t exclfr = kFALSE;
00524 Bool_t exclbases = kFALSE;
00525
00526 if (frame) {
00527 TPair* exclpair = (TPair*) fExclMap.FindObject(cl);
00528 if (exclpair) {
00529 exclfr = kTRUE;
00530 exclbases = (exclpair->Value() != 0);
00531 }
00532
00533 if (!exclfr && frame->AcceptModel(fModel)){
00534
00535 if (frame->GetExtraTabs()) {
00536 TIter next(frame->GetExtraTabs());
00537 TGedFrame::TGedSubFrame* subf;
00538 while ((subf = (TGedFrame::TGedSubFrame*)next())) {
00539
00540 TGedTabInfo* ti = GetEditorTabInfo(subf->fName);
00541 ti->fContainer->AddFrame(subf->fFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
00542 if (fVisibleTabs.FindObject(ti) == 0)
00543 fVisibleTabs.Add(ti);
00544 }
00545 }
00546 InsertGedFrame(frame);
00547 }
00548 }
00549
00550 if (recurse && !exclbases) {
00551 if (frame)
00552 frame->ActivateBaseClassEditors(cl);
00553 else
00554 ActivateEditors(cl->GetListOfBases(), recurse);
00555 }
00556 }
00557
00558
00559 void TGedEditor::ActivateEditors(TList* bcl, Bool_t recurse)
00560 {
00561
00562
00563 TBaseClass *base;
00564 TIter next(bcl);
00565
00566 while ((base = (TBaseClass*) next())) {
00567 ActivateEditor(base->GetClassPointer(), recurse);
00568 }
00569 }
00570
00571
00572 void TGedEditor::ExcludeClassEditor(TClass* cl, Bool_t recurse)
00573 {
00574
00575
00576
00577 TPair* pair = (TPair*) fExclMap.FindObject(cl);
00578 if (pair) {
00579 if (recurse && pair->Value() == 0)
00580 pair->SetValue((TObject*)(Long_t)1);
00581 } else {
00582 fExclMap.Add(cl, (TObject*)(Long_t)(recurse ? 1 : 0));
00583 }
00584 }
00585
00586
00587 void TGedEditor::InsertGedFrame(TGedFrame* f)
00588 {
00589
00590
00591
00592 TObjLink* lnk = fGedFrames.FirstLink();
00593 if (lnk == 0) {
00594 fGedFrames.Add(f);
00595 return;
00596 }
00597 TGedFrame* cf;
00598 while (lnk) {
00599 cf = (TGedFrame*) lnk->GetObject();
00600 if (f->GetPriority() < cf->GetPriority()) {
00601 fGedFrames.AddBefore(lnk, f);
00602 return;
00603 }
00604 lnk = lnk->Next();
00605 }
00606 fGedFrames.Add(f);
00607 }
00608
00609
00610 void TGedEditor::ConfigureGedFrames(Bool_t objChanged)
00611 {
00612
00613
00614 TGFrameElement *el;
00615
00616
00617
00618 TIter vistabs(&fVisibleTabs);
00619 vistabs();
00620 TGedTabInfo* ti;
00621 while ((ti = (TGedTabInfo *) vistabs())) {
00622 TIter fr(ti->fContainer->GetList());
00623 el = (TGFrameElement*) fr();
00624 if (el) {
00625 ((TGedFrame*) el->fFrame)->SetModel(fModel);
00626 if (objChanged) {
00627 do {
00628 el->fFrame->MapSubwindows();
00629 el->fFrame->Layout();
00630 el->fFrame->MapWindow();
00631 } while((el = (TGFrameElement *) fr()));
00632 }
00633 }
00634 ti->fContainer->Layout();
00635 }
00636
00637 TIter next(fTabContainer->GetList());
00638 while ((el = (TGFrameElement *) next())) {
00639 if ((el->fFrame)->InheritsFrom(TGedFrame::Class())) {
00640 if (objChanged) {
00641 el->fFrame->MapSubwindows();
00642 ((TGedFrame *)(el->fFrame))->SetModel(fModel);
00643 el->fFrame->Layout();
00644 el->fFrame->MapWindow();
00645 } else {
00646 ((TGedFrame *)(el->fFrame))->SetModel(fModel);
00647 }
00648 }
00649 }
00650 fTabContainer->Layout();
00651 }
00652
00653
00654 TGedFrame* TGedEditor::CreateNameFrame(const TGWindow* parent, const char* )
00655 {
00656
00657
00658 return new TGedNameFrame(parent);
00659 }
00660
00661
00662 void TGedEditor::PrintFrameStat()
00663 {
00664
00665
00666 printf("TGedEditor::PrintFrameStat()\n");
00667 Int_t sum = 0;
00668 TIter next(fFrameMap.GetTable());
00669 TPair* pair;
00670 while ((pair = (TPair*) next())) {
00671 if (pair->Value() != 0) {
00672 TClass* cl = (TClass*) pair->Key();
00673 printf("TGedFrame created for %s \n", cl->GetName());
00674 sum ++;
00675 }
00676 }
00677 printf("SUMMARY: %d editors stored in the local map.\n", sum);
00678 }