diff --git a/ged/inc/TGedEditor.h b/ged/inc/TGedEditor.h
index 4acc1d792219200a15c01127bb9b7b683d72ea31..13a4941bb3b314b38e889ac484006a47b3623005 100644
--- a/ged/inc/TGedEditor.h
+++ b/ged/inc/TGedEditor.h
@@ -1,4 +1,4 @@
-// @(#)root/ged:$Name:  $:$Id: TGedEditor.h,v 1.8 2006/05/23 04:47:36 brun Exp $
+// @(#)root/ged:$Name:  $:$Id: TGedEditor.h,v 1.9 2006/07/26 13:36:42 rdm Exp $
 // Author: Marek Biskup, Ilka Antcheva   02/12/2003
 
 /*************************************************************************
@@ -30,53 +30,81 @@
 #include "TVirtualPadEditor.h"
 #endif
 
+#include "TMap.h"
+
 class TCanvas;
 class TGCanvas;
 class TGTab;
+class TGTabElement;
 class TVirtualPad;
 class TGedFrame;
-class TGedElement;
+class TGedNameFrame;
+
+class TGedTabInfo;
 
-class TGedEditor : public TVirtualPadEditor, public TGMainFrame {
+class TGedEditor : public TVirtualPadEditor, public TGMainFrame
+{
+private:
+   TGedEditor(const TGedEditor&);            // Not implemented
+   TGedEditor& operator=(const TGedEditor&); // Not implemented
 
 protected:
+   TMap              fFrameMap;         //global map of available frames
+   TMap              fExclMap;          //map of excluded editors for selected model
+   TList             fGedFrames;        //list visible of frames 
+
    TGCanvas         *fCan;              //provides scroll bars
    TGTab            *fTab;              //tab widget holding the editor
+
+   TList             fCreatedTabs;      //list of created tabs
+   TList             fVisibleTabs;      //list ofcurrently used tabs
    TGCompositeFrame *fTabContainer;     //main tab container
-   TGCompositeFrame *fStyle;            //style tab container frame
+
    TObject          *fModel;            //selected object
    TVirtualPad      *fPad;              //selected pad
    TCanvas          *fCanvas;           //canvas related to the editor
    TClass           *fClass;            //class of the selected object
-   Int_t             fWid;              //widget id
    Bool_t            fGlobal;           //true if editor is global
 
-   virtual void GetEditors();
-   virtual void GetClassEditor(TClass *cl);
-   virtual void GetBaseClassEditor(TClass *cl);
-
-private:
-   TGedEditor(const TGedEditor&);              // not implemented
-   TGedEditor& operator=(const TGedEditor&);   // not implemented
+   void              ConfigureGedFrames();
 
 public:
    TGedEditor(TCanvas* canvas = 0);
    virtual ~TGedEditor();
 
+   void          PrintFrameStat();
+   virtual void  Update(TGedFrame* frame = 0);
+   void          ReinitWorkspace();
+   void          ActivateEditor (TClass* cl, Bool_t recurse);
+   void          ActivateEditors(TList* bcl, Bool_t recurse);
+   void          ExcludeClassEditor(TClass* cl, Bool_t recurse = kFALSE);
+   void          InsertGedFrame(TGedFrame* f);
+
+   TGCanvas*                 GetTGCanvas() const { return fCan; }
+   TGTab*                    GetTab()      const { return fTab; }
+   virtual TGCompositeFrame* GetEditorTab(const Text_t* name);
+   virtual TGedTabInfo*      GetEditorTabInfo(const Text_t* name);
+   virtual TGCompositeFrame* CreateEditorTabSubFrame(const Text_t* name, TGedFrame* owner);
+
+   virtual TCanvas*          GetCanvas() const { return fCanvas; }
+   virtual TVirtualPad*      GetPad()    const { return fPad; }
+   virtual TObject*          GetModel()  const { return fModel; }
+
+public:
+
    virtual void   CloseWindow();
    virtual void   ConnectToCanvas(TCanvas *c);
-   virtual void   DeleteEditors();
-   virtual void   DisconnectEditors(TCanvas *canvas);
-   TCanvas       *GetCanvas() const { return fCanvas; }
-   virtual Bool_t IsGlobal() const { return fGlobal; }
+   virtual void   DisconnectFromCanvas();
+   virtual Bool_t IsGlobal() const  { return fGlobal; } 
    virtual void   Hide();
+   virtual void   GlobalClosed();
    virtual void   SetCanvas(TCanvas *c);
-   virtual void   SetGlobal(Bool_t global) { fGlobal = global; }
+   virtual void   SetGlobal(Bool_t global);
+   virtual void   GlobalSetModel(TVirtualPad *, TObject *, Int_t);
    virtual void   SetModel(TVirtualPad* pad, TObject* obj, Int_t event);
    virtual void   Show();
    virtual void   RecursiveRemove(TObject* obj);
-
-   ClassDef(TGedEditor,0)  //new editor
+   ClassDef(TGedEditor,0) 
 };
 
 #endif
diff --git a/ged/src/TGedEditor.cxx b/ged/src/TGedEditor.cxx
index 481daf41d9de83028420a23311b306951e96155d..9580c7439e01f17db7703b1deb14bfe45302a5f3 100644
--- a/ged/src/TGedEditor.cxx
+++ b/ged/src/TGedEditor.cxx
@@ -1,4 +1,4 @@
-// @(#)root/ged:$Name:  $:$Id: TGedEditor.cxx,v 1.29 2006/06/23 15:19:22 antcheva Exp $
+// @(#)root/ged:$Name:  $:$Id: TGedEditor.cxx,v 1.26 2006/03/20 21:43:41 pcanal Exp $
 // Author: Marek Biskup, Ilka Antcheva 02/08/2003
 
 /*************************************************************************
@@ -20,7 +20,7 @@
 //                                                                      //
 //////////////////////////////////////////////////////////////////////////
 
-#include "TGedEditor.h"
+#include "TGedEditor.h" 
 #include "TCanvas.h"
 #include "TGCanvas.h"
 #include "TGTab.h"
@@ -31,64 +31,57 @@
 #include "TBaseClass.h"
 #include "TSystem.h"
 
+class TGedTabInfo : public TObject {
+   // Helper class for managing visibility and order of created tabs.
+public:
+   TGTabElement      *fElement;
+   TGCompositeFrame  *fContainer;
+
+   TGedTabInfo(TGTabElement* el, TGCompositeFrame* f) : 
+      fElement(el), fContainer(f) {}
+};
 
-ClassImp(TGedEditor)
 
+ClassImp(TGedEditor)
 //______________________________________________________________________________
 TGedEditor::TGedEditor(TCanvas* canvas) :
-   TGMainFrame(gClient->GetRoot(), 175, 20)
+   TGMainFrame(gClient->GetRoot(), 175, 20),
+   fCan          (0),
+   fTab          (0),
+   fTabContainer (0),
+   fModel        (0),
+   fPad          (0),
+   fCanvas       (0),
+   fClass        (0),
+   fGlobal       (kTRUE)
 {
    // Constructor of graphics editor.
 
-   fCan = new TGCanvas(this, 170, 10, kFixedWidth);
-   fTab = new TGTab(fCan->GetViewPort(), 10, 10);
-   fCan->SetContainer(fTab);
+   fCan = new TGCanvas(this, 170, 10, kFixedWidth); 
    AddFrame(fCan, new TGLayoutHints(kLHintsExpandY | kLHintsExpandX));
+
+   fTab = new TGTab(fCan->GetViewPort(), 10, 10);
    fTab->Associate(fCan);
-   fTabContainer = fTab->AddTab("Style");
-   fStyle = new TGCompositeFrame(fTabContainer, 110, 30, kVerticalFrame);
-   fStyle->AddFrame(new TGedNameFrame(fStyle, 1),\
-                    new TGLayoutHints(kLHintsTop | kLHintsExpandX,0, 0, 2, 2));
-   fTabContainer->AddFrame(fStyle, new TGLayoutHints(kLHintsTop | kLHintsExpandX,\
-                                                     5, 0, 2, 2));
-   fWid = GetCounter();
-   fGlobal = kTRUE;
-
-   if (canvas) {
-      if (!canvas->GetSelected())
-         canvas->SetSelected(canvas);
-      if (!canvas->GetSelectedPad())
-         canvas->SetSelectedPad(canvas);
-      fModel  = canvas->GetSelected();
-      fPad    = canvas->GetSelectedPad();
-      fCanvas = canvas;
-      fClass  = fModel->IsA();
-      GetEditors();
-      SetWindowName(Form("%s_Editor", canvas->GetName()));
-   } else {
-      fModel  = 0;
-      fPad    = 0;
-      fCanvas = 0;
-      fClass  = 0;
-      if (gPad) SetCanvas(gPad->GetCanvas());
-      SetWindowName("Global Editor");
-   }
-   MapSubwindows();
-   if (canvas) {
+   fTab->SetCleanup(kDeepCleanup);
+   fCan->SetContainer(fTab);
+
+   fTabContainer = GetEditorTab("Style");
+
+   gROOT->GetListOfCleanups()->Add(this);
+
+   SetCanvas(canvas);
+   if (fCanvas) {
       UInt_t ch = fCanvas->GetWindowHeight();
       if (ch)
          Resize(GetWidth(), ch > 700 ? 700 : ch);
       else
-         Resize(GetWidth(), canvas->GetWh()<450 ? 450 : canvas->GetWh() + 4);
-                                                       // canvas borders=4pix
+         Resize(GetWidth(), fCanvas->GetWh()<450 ? 450 : fCanvas->GetWh() + 4);
    } else {
       Resize(GetDefaultSize());
    }
-   MapWindow();
-
-   gROOT->GetListOfCleanups()->Add(this);
-   if (fCanvas) ConnectToCanvas(fCanvas);
 
+   MapSubwindows();
+   MapWindow();
 }
 
 //______________________________________________________________________________
@@ -96,139 +89,206 @@ TGedEditor::~TGedEditor()
 {
    // Editor destructor.
 
-   gROOT->GetListOfCleanups()->Remove(this);
+   Hide();
 
-   fStyle->Cleanup();
-   //Cleanup() cannot be used because of TH1/2Editors
-   delete fTab;       //delete tab widget and its containers
-   delete fCan;       //delete TGCanvas
+   if(fGlobal){
+      TQObject::Disconnect("TCanvas", "Selected(TVirtualPad *, TObject *, Int_t)");
+      TQObject::Disconnect("TCanvas", "Closed()"); 
+   }
+
+   // delete class editors
+   TIter next(fFrameMap.GetTable());
+   TPair* pair;
+   while ((pair = (TPair*) next())) {
+      if (pair->Value() != 0) {
+         TGedFrame* frame  = (TGedFrame*) pair->Value();
+         delete frame;
+      }
+   }
+
+   TGedTabInfo* ti;
+   TIter it1(&fCreatedTabs);
+   while ((ti = (TGedTabInfo*) it1())) {
+      fTab->AddFrame(ti->fElement,0);
+      fTab->AddFrame(ti->fContainer,0);
+   }
+
+   delete fTab;
+   delete ((TGFrameElement*)fList->First())->fLayout;
+   delete fCan;
 }
 
 //______________________________________________________________________________
-void TGedEditor::CloseWindow()
+void TGedEditor::Update(TGedFrame* /*frame*/)
 {
-   // When closed via WM close button, just unmap (i.e. hide) editor
-   // for later use.
+   // Virtual method that is called on any change in the dependent frames.
+   // This implementation simply calls fPad Modified()/Update().
 
-   UnmapWindow();
-   Disconnect(fCanvas, "Selected(TVirtualPad*,TObject*,Int_t)", this, "SetModel(TVirtualPad*,TObject*,Int_t)");
-   gROOT->GetListOfCleanups()->Remove(this);
+   if (fPad) {
+      fPad->Modified();
+      fPad->Update();
+   }
 }
 
 //______________________________________________________________________________
-void TGedEditor::GetEditors()
+TGCompositeFrame* TGedEditor::GetEditorTab(const Text_t* name)
 {
-   // Get existing editors of selected object
-
-   // Look in TClass::GetEditorList() for any object deriving from TGedFrame,
-   Bool_t found = kFALSE;
-   TGedElement *ge;
-   TList *list = fModel->IsA()->GetEditorList();
-   if (list->First() != 0) {
-
-      TIter next1(list);
-      while ((ge = (TGedElement *) next1())) {
-         // check if the editor ge->fGedframe is already in the list of fStyle
-         TList *l = fStyle->GetList();
-         if (l->First() != 0) {
-            TGFrameElement *fr;
-            TIter next(l);
-            while ((fr = (TGFrameElement *) next())) {
-               TGedFrame *f = ge->fGedFrame;
-               found = (fr->fFrame->InheritsFrom(f->ClassName()) && (ge->fCanvas == fCanvas));
-               if (found) break;
-               else {
-                  GetClassEditor(fModel->IsA());
-                  TList *blist = fModel->IsA()->GetListOfBases();
-                  if (blist->First() != 0)
-                     GetBaseClassEditor(fModel->IsA());
-               }
-            }
-         }
+   // Find or create tab with name.
+   return GetEditorTabInfo(name)->fContainer;
+}
+
+//______________________________________________________________________________
+TGedTabInfo* TGedEditor::GetEditorTabInfo(const Text_t* name)
+{
+   // Find or create tab with name.
+
+   // look in list of created tabs
+   if ( ! fCreatedTabs.IsEmpty()) {
+      TIter next(&fCreatedTabs);
+      TGedTabInfo* ti;
+      while ((ti = (TGedTabInfo *) next())) {
+         if (*ti->fElement->GetText() == name)
+            return ti;
       }
-   } else {
+   }
 
-      // scan list of base classes
-      list = fModel->IsA()->GetListOfBases();
-      if (list->First() != 0)
-         GetBaseClassEditor(fModel->IsA());
+   // create tab
+   TGCompositeFrame* tc = fTab->AddTab(new TGString(name));
 
-      //search for a class editor = classname + 'Editor'
-      GetClassEditor(fModel->IsA());
-   }
+   // remove created frame end tab element from the fTab frame
+   TGTabElement *te = fTab->GetTabTab(fTab->GetNumberOfTabs() - 1);
+   fTab->RemoveFrame(tc);
+   fTab->RemoveFrame(te);
 
-   fStyle->Layout();
-   fStyle->MapSubwindows();
+   // create a title frame for each tab
+   TGedNameFrame* nf = new TGedNameFrame(tc);
+   nf->SetGedEditor(this);
+   nf->SetModelClass(0);
+   tc->AddFrame(nf, nf->GetLayoutHints());
+
+   // add to list of created tabs
+   TGedTabInfo* ti = new TGedTabInfo(te, tc);
+   fCreatedTabs.Add(ti);
+
+   return ti;
 }
 
 //______________________________________________________________________________
-void TGedEditor::GetBaseClassEditor(TClass *cl)
+TGCompositeFrame* TGedEditor::CreateEditorTabSubFrame(const Text_t* name,
+                                                      TGedFrame* owner)
 {
-   // Scan the base classes of cl and add attribute editors to the list.
+   // Create a vertical frame to be used by 'owner' in extra tab 'name'.
+   // The new frame is registered into the sub-frame listo of 'owner'.
 
-   TList *list = cl->GetListOfBases();
-   if (list->First() == 0) return;
+   TGCompositeFrame* tabcont  = GetEditorTab(name);
 
-   TBaseClass *base;
-   TIter next(list);
+   TGCompositeFrame* newframe = new TGVerticalFrame(tabcont);
+   owner->AddExtraTab(new TGedFrame::TGedSubFrame(TString(name), newframe));
+   return newframe;
+}
 
-   while ((base = (TBaseClass *)next())) {
+//______________________________________________________________________________
+void TGedEditor::CloseWindow()
+{
+   // Called when closed via WM close button. Calls Hide().
+
+   Hide();
+}
 
-      TClass *c1;
-      if ((c1 = base->GetClassPointer())) GetClassEditor(c1);
+//______________________________________________________________________________
+void TGedEditor::ReinitWorkspace()
+{  
+   // Clears windows in editor tab.
+   // Moves all visible GedFrames to the map of available frames and hide them. 
+
+   TIter it(fTabContainer->GetList());
+   it(); // skip name-frame
+
+   // Unmap and withdraw currently shown frames and thus prepare for
+   // construction of a new class layout or destruction.
+   TIter next(&fVisibleTabs);
+   TGedTabInfo* ti;
+   while ((ti = (TGedTabInfo*)next())) {
+      TGTabElement     *te = ti->fElement;
+      TGCompositeFrame *tc = ti->fContainer;
+
+      fTab->RemoveFrame(te);
+      fTab->RemoveFrame(tc);
+
+      // printf("ReinitWorkspace remove %d from %s \n", tc->GetList()->GetSize(),tc->GetName());
+      TIter frames(tc->GetList());
+      frames(); // skip name-frame
+      TGFrameElement* fr;
+      while ((fr = (TGFrameElement *) frames()) != 0) {
+         TGFrame *f = fr->fFrame;
+         {
+            tc->RemoveFrame(f);
+            f->UnmapWindow();
+         }
+         te->UnmapWindow();
+         tc->UnmapWindow();
 
-      if (c1->GetListOfBases()->First() == 0) continue;
-      else GetBaseClassEditor(c1);
+         fVisibleTabs.Remove(ti);
+      }
    }
 }
 
 //______________________________________________________________________________
-void TGedEditor::GetClassEditor(TClass *cl)
+void TGedEditor::SetGlobal(Bool_t global)
 {
-   // Add attribute editor of class cl to the list of fStyle frame.
-
-   TClass *class2, *class3;
-   Bool_t found = kFALSE;
-   class2 = gROOT->GetClass(Form("%sEditor",cl->GetName()));
-   if (class2 && class2->InheritsFrom(TGedFrame::Class())) {
-      TList *list = fStyle->GetList();
-      if (list->First() != 0) {
-         TGFrameElement *fr;
-         TIter next(list);
-         while ((fr = (TGFrameElement *) next())) {;
-            found = fr->fFrame->InheritsFrom(class2);
-            if (found) break;
-         }
-      }
-      if (found == kFALSE) {
-         gROOT->ProcessLine(Form("((TGCompositeFrame *)0x%lx)->AddFrame(new %s((TGWindow *)0x%lx, %d),\
-                                 new TGLayoutHints(kLHintsTop | kLHintsExpandX,0, 0, 2, 2))",\
-                                 (Long_t)fStyle, class2->GetName(), (Long_t)fStyle, fWid));
-         fWid++;
-         class3 = (TClass*)gROOT->GetListOfClasses()->FindObject(cl->GetName());
-         TGedElement *ge;
-         TIter next3(class3->GetEditorList());
-         while ((ge = (TGedElement *)next3())) {
-            if (!strcmp(ge->fGedFrame->ClassName(), class2->GetName()) && (ge->fCanvas == 0)) {
-               ge->fCanvas = fCanvas;
-            }
-         }
-      }
+   // Set editor global.
+
+   fGlobal = global;
+   if (fGlobal) {
+      TQObject::Connect("TCanvas", "Selected(TVirtualPad *, TObject *, Int_t)",
+                        "TGedEditor", this, "GlobalSetModel(TVirtualPad *, TObject *, Int_t)"); 
+       
+      TQObject::Connect("TCanvas", "Closed()",
+                        "TGedEditor", this, "GlobalClosed()");
    }
 }
 
+//______________________________________________________________________________
+void TGedEditor::GlobalClosed()
+{
+   // Delete global editor if no canvas exists.
+
+   if (gROOT->GetListOfCanvases()->IsEmpty())
+      TVirtualPadEditor::Terminate();
+}
+
+//______________________________________________________________________________
+void TGedEditor::GlobalSetModel(TVirtualPad *pad, TObject */*obj*/, Int_t ev)
+{
+   // Set canvas to global editor.
+
+   if (ev != kButton1Down) return;
+
+   TCanvas* can = pad->GetCanvas();
+   // Do nothing if canvas is the same as before or
+   // local editor of the canvas is active.
+   if (can == fCanvas || can->GetShowEditor())
+      return;
+
+   Show();
+}
+
 //______________________________________________________________________________
 void TGedEditor::ConnectToCanvas(TCanvas *c)
 {
-   // Connect this editor to the selected object in the canvas 'c'.
-
-   c->Connect("Selected(TVirtualPad*,TObject*,Int_t)", "TGedEditor",\
-               this, "SetModel(TVirtualPad*,TObject*,Int_t)");
-   if (!c->GetSelected())
-      c->SetSelected(c);
-   if (!c->GetSelectedPad())
-      c->SetSelectedPad(c);
-   c->Selected(c->GetSelectedPad(), c->GetSelected(), kButton1Down);
+   // Connect this editor to the Selected signal of canvas 'c'.
+
+   c->Connect("Selected(TVirtualPad*,TObject*,Int_t)", "TGedEditor",
+              this, "SetModel(TVirtualPad*,TObject*,Int_t)");
+}
+
+//______________________________________________________________________________
+void TGedEditor::DisconnectFromCanvas()
+{
+   // Disconnect this editor from the Selected signal of fCanvas.
+
+   if (fCanvas)
+      Disconnect(fCanvas, "Selected(TVirtualPad*,TObject*,Int_t)", this, "SetModel(TVirtualPad*,TObject*,Int_t)");
 }
 
 //______________________________________________________________________________
@@ -236,23 +296,15 @@ void TGedEditor::SetCanvas(TCanvas *newcan)
 {
    // Change connection to another canvas.
 
-   if (!newcan || !fCanvas || (fCanvas == newcan)) return;
+   if (!newcan || (fCanvas == newcan)) return;
 
-   if (fCanvas && (fCanvas != newcan))
-      DisconnectEditors(fCanvas);
+   DisconnectFromCanvas();
    fCanvas = newcan;
 
    SetWindowName(Form("%s_Editor", fCanvas->GetName()));
-   if (!fCanvas->GetSelected())
-      fCanvas->SetSelected(newcan);
-   if (!fCanvas->GetSelectedPad())
-      fCanvas->SetSelectedPad(newcan);
-   fModel  = fCanvas->GetSelected();
-   fPad    = fCanvas->GetSelectedPad();
-   fClass  = fModel->IsA();
-   GetEditors();
+   fPad = fCanvas->GetSelectedPad();
+   if (fPad == 0) fPad = fCanvas;
    ConnectToCanvas(fCanvas);
-   SetModel(fPad, fModel, kButton1Down);
 }
 
 //______________________________________________________________________________
@@ -260,39 +312,65 @@ void TGedEditor::SetModel(TVirtualPad* pad, TObject* obj, Int_t event)
 {
    // Activate object editors according to the selected object.
 
-   if (!fGlobal && (event != kButton1Down)) return;
+   if (event != kButton1Down) return;
 
-   TCanvas *c = (TCanvas *) gTQSender;
+   if (gPad) gPad->GetVirtCanvas()->SetCursor(kWatch);
+   gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kWatch));
+ 
+   fPad = pad;
+   if (obj == 0) obj = fPad;
+
+   // keep selected by name
+   TGTabElement* seltab = fTab->GetCurrentTab();
+
+   Bool_t mapTabs = kFALSE;
+   if (fModel != obj) {
+      fModel = obj;
+      if (fModel == 0 || fModel->IsA() != fClass) {
+         ReinitWorkspace();
+         mapTabs = kTRUE;
+         // add Sytle tab to list of visible tabs
+         fVisibleTabs.Add(fCreatedTabs.First());
+         if (fModel) {
+            fClass = fModel->IsA();
+            // build a list of editors
+            ActivateEditor(fClass, kTRUE);
+         } else {
+            fClass = 0;
+         }
 
-   if (!fGlobal && (c != fCanvas)) return;
+         // add class editors to fTabContainer
+         TGedFrame* gfr;
+         TIter ngf(&fGedFrames);
+         while ((gfr = (TGedFrame*) ngf()))
+            fTabContainer->AddFrame(gfr, gfr->GetLayoutHints());
+
+         fExclMap.Clear();
+         fGedFrames.Clear();
+
+         // add visible tabs in fTab
+         TIter next(&fVisibleTabs);
+         TGedTabInfo* ti;
+         while ((ti = (TGedTabInfo *) next())) {
+            fTab->AddFrame(ti->fElement,0);
+            fTab->AddFrame(ti->fContainer,0);
+         }  
+      }
+   } // end fModel != obj
 
-   fModel = obj;
-   fPad   = pad;
+   ConfigureGedFrames();
 
-   if ((obj != 0) && (obj->IsA() != fClass) && !obj->IsA()->InheritsFrom(fClass)) {
-      fClass = obj->IsA();
-      GetEditors();
-   } else if ((obj == 0) && fPad) {
-      TCanvas *canvas = fPad->GetCanvas();
-      if (canvas) {
-         fPad->SetSelected(fPad);
-         canvas->Selected(fPad, fPad, 0);
-         return;
-      } else {
-         DeleteEditors();
-         DeleteWindow();
-         return;
+   if (mapTabs) { // selected object is different class
+      TGedTabInfo* ti;
+      TIter next(&fVisibleTabs);
+      while ((ti = (TGedTabInfo *) next())) {
+         ti->fElement->MapWindow();
+         ti->fContainer->MapWindow();
       }
-   }
-   if (gPad) gPad->GetVirtCanvas()->SetCursor(kWatch);
-   gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kWatch));
+      if (seltab == 0 || fTab->SetTab(seltab->GetString(), kFALSE) == kFALSE)
+         fTab->SetTab(0, kFALSE);
+   } 
 
-   TGFrameElement *el;
-   TIter next(fStyle->GetList());
-   while ((el = (TGFrameElement *) next())) {
-      if ((el->fFrame)->InheritsFrom(TGedFrame::Class()))
-         ((TGedFrame *)(el->fFrame))->SetModel(fPad, fModel, event);
-   }
    if (fGlobal)
       Layout();
    else
@@ -307,22 +385,22 @@ void TGedEditor::Show()
 {
    // Show editor.
 
-   if (gPad && (gPad->GetCanvas() != fCanvas))
-      SetCanvas(gPad->GetCanvas());
-   else
-      ConnectToCanvas(fCanvas);
-
-   if (fCanvas->GetShowEditor())
-      fCanvas->ToggleEditor();
+   // gPad is setup properly in calling code for global and canvas editor.
+   SetCanvas(gPad->GetCanvas());
 
    if (fGlobal) {
+      SetModel(fCanvas->GetClickSelectedPad(), fCanvas->GetClickSelected(), kButton1Down);
+
+      if (fCanvas->GetShowEditor())
+         fCanvas->ToggleEditor();
+
       UInt_t dw = fClient->GetDisplayWidth();
       UInt_t cw = fCanvas->GetWindowWidth();
       UInt_t ch = fCanvas->GetWindowHeight();
       UInt_t cx = (UInt_t)fCanvas->GetWindowTopX();
       UInt_t cy = (UInt_t)fCanvas->GetWindowTopY();
-      if (!ch)
-         cy = cy + 20;      // embedded canvas protection
+      if (!ch) 
+         cy = cy + 20;      // embeded canvas protection
 
       Int_t gedx = 0, gedy = 0;
 
@@ -338,8 +416,12 @@ void TGedEditor::Show()
       }
       MoveResize(gedx, gedy, GetWidth(), ch > 700 ? 700 : ch);
       SetWMPosition(gedx, gedy);
+   } else {
+      SetModel(fCanvas, fCanvas, kButton1Down);
    }
    MapWindow();
+   gVirtualX->RaiseWindow(GetId());
+
    if (!gROOT->GetListOfCleanups()->FindObject(this))
       gROOT->GetListOfCleanups()->Add(this);
 }
@@ -347,90 +429,197 @@ void TGedEditor::Show()
 //______________________________________________________________________________
 void TGedEditor::Hide()
 {
-   // Hide editor.
+   // Hide editor. The editor is put into non-active state.
 
-   if (gPad->GetCanvas() == fCanvas) {
-      UnmapWindow();
-      Disconnect(fCanvas, "Selected(TVirtualPad*,TObject*,Int_t)", this, "SetModel(TVirtualPad*,TObject*,Int_t)");
-      gROOT->GetListOfCleanups()->Remove(this);
+   UnmapWindow();
+   ReinitWorkspace();
+   fModel = 0; fClass = 0;
+   DisconnectFromCanvas();
+   fCanvas = 0; fPad = 0;
+   gROOT->GetListOfCleanups()->Remove(this);
+}
+
+//______________________________________________________________________________
+void TGedEditor::RecursiveRemove(TObject* obj)
+{
+   // Remove references to fModel in case the fModel is being deleted.
+   // Deactivate attribute frames if they point to obj.
+  
+   if (obj == fPad) {
+      // printf("TGedEditor::RecursiveRemove: %s - pad deleted.\n", locglob);
+      SetModel(fCanvas, fCanvas, kButton1Down);
+      return;
+   }
+
+   if (obj == fModel) {
+      // printf("TGedEditor::RecursiveRemove: %s - model deleted.\n", locglob);
+      SetModel(fPad, fPad, kButton1Down);
+      return;
    }
 }
 
 //______________________________________________________________________________
-void TGedEditor::DisconnectEditors(TCanvas *canvas)
+void TGedEditor::ActivateEditor(TClass* cl, Bool_t recurse)
 {
-   // Disconnect GUI editors connected to canvas.
-
-   if (!canvas) return;
-
-   Disconnect(canvas, "Selected(TVirtualPad*,TObject*,Int_t)", this, "SetModel(TVirtualPad*,TObject*,Int_t)");
-
-   TClass * cl;
-   TIter next(gROOT->GetListOfClasses());
-   while((cl = (TClass *)next())) {
-      if (cl->GetEditorList()->First() != 0) {
-         TList *editors = cl->GetEditorList();
-         TIter next1(editors);
-         TGedElement *ge;
-         while ((ge = (TGedElement *)next1())) {
-            if (ge->fCanvas == canvas) {
-               ge->fCanvas = 0;
+   // Searches for GedFrames for given class. In recursive mode look for class 
+   // editor in its list of bases.
+
+   TPair     *pair = (TPair*) fFrameMap.FindObject(cl);
+   TClass    *edClass = 0;
+   TGedFrame *frame = 0;
+
+   if (pair == 0) {
+      edClass = gROOT->GetClass(Form("%sEditor", cl->GetName()));
+
+      if (edClass && edClass->InheritsFrom(TGedFrame::Class())) {
+         frame = reinterpret_cast<TGedFrame*>(edClass->New());
+         frame->ReparentWindow(fTabContainer);
+         frame->SetModelClass(cl);
+         frame->SetGedEditor(this);
+      }
+      fFrameMap.Add(cl, frame);
+   } else {
+      frame =  (TGedFrame*)pair->Value();
+   }
+
+   Bool_t exclfr    = kFALSE;
+   Bool_t exclbases = kFALSE;
+
+   if (frame) {
+      TPair* exclpair = (TPair*) fExclMap.FindObject(cl);
+      if (exclpair) {
+         exclfr = kTRUE;
+         exclbases = (exclpair->Value() != 0);
+      }
+
+      if (!exclfr && frame->AcceptModel(fModel)){
+         // handle extra tabs in the gedframe
+         if (frame->GetExtraTabs()) {
+            TIter next(frame->GetExtraTabs());
+            TGedFrame::TGedSubFrame* subf;
+            while ((subf = (TGedFrame::TGedSubFrame*)next())) {
+               // locate the composite frame on created tabs
+               TGedTabInfo* ti = GetEditorTabInfo(subf->fName);
+               ti->fContainer->AddFrame(subf->fFrame);
+               if(! pair)
+                  subf->fFrame->ReparentWindow(ti->fContainer);
+               fVisibleTabs.Add(ti);
             }
          }
+         InsertGedFrame(frame);
       }
+   }    
+
+   if (recurse && !exclbases) {
+      if (frame)
+         frame->ActivateBaseClassEditors(cl);
+      else
+         ActivateEditors(cl->GetListOfBases(), recurse);
    }
 }
 
 //______________________________________________________________________________
-void TGedEditor::DeleteEditors()
+void TGedEditor::ActivateEditors(TList* bcl, Bool_t recurse)
 {
-   // Delete GUI editors connected to the canvas fCanvas.
-
-   DisconnectEditors(fCanvas);
-   Bool_t del = kTRUE;
-
-   TClass * cl;
-   TIter next(gROOT->GetListOfClasses());
-
-   while((cl = (TClass *)next())) {
-      if (cl->GetEditorList()->First() != 0) {
-         TList *editors = cl->GetEditorList();
-         TIter next1(editors);
-         TGedElement *ge;
-         while ((ge = (TGedElement *)next1())) {
-            if (ge->fCanvas != 0) {
-               del = kFALSE;
-            }
-         }
-      }
+   // Searches GedFrames for classes in the given list.
+
+   TBaseClass *base;
+   TIter next(bcl);
+
+   while ((base = (TBaseClass*) next())) {
+      ActivateEditor(base->GetClassPointer(), recurse);
    }
+}
 
-   if (del) {
-      TIter next(gROOT->GetListOfClasses());
-      while((cl = (TClass *)next())) {
-         if (cl->GetEditorList()->First() != 0) {
-            TList *editors = cl->GetEditorList();
-            TIter next1(editors);
-            TGedElement *ge;
-            while ((ge = (TGedElement *)next1())) {
-               editors->Remove(ge);
-               delete ge;
-            }
-         }
+//______________________________________________________________________________
+void  TGedEditor::ExcludeClassEditor(TClass* cl, Bool_t recurse)
+{
+   // Exclude editor for class cl from current construction.
+   // If recurse is true the base-class editors of cl are also excluded.
+
+   TPair* pair = (TPair*) fExclMap.FindObject(cl);
+   if (pair) {
+      if (recurse && pair->Value() == 0)
+         pair->SetValue((TObject*)1); // hack, reuse TObject as Bool_t
+   } else {
+      fExclMap.Add(cl, (TObject*)(recurse ? 1 : 0));
+   }
+}
+
+//______________________________________________________________________________
+void TGedEditor::InsertGedFrame(TGedFrame* f)
+{
+   // Insert GedFrame in fGedFrames list according to priorities.
+
+   // printf("%s %s  insert gedframe %s \n", fModel->GetName(), fModel->IsA()->GetName(),f->GetModelClass()->GetName());
+   TObjLink* lnk = fGedFrames.FirstLink();
+   if (lnk == 0) {
+      fGedFrames.Add(f);
+      return;
+   }
+   TGedFrame* cf;
+   while (lnk) {
+      cf = (TGedFrame*) lnk->GetObject();
+      if (f->GetPriority() < cf->GetPriority()) {
+         fGedFrames.AddBefore(lnk, f);
+         return;
       }
+      lnk = lnk->Next();
    }
+   fGedFrames.Add(f);
 }
 
 //______________________________________________________________________________
-void TGedEditor::RecursiveRemove(TObject* obj)
+void TGedEditor::ConfigureGedFrames()
 {
-   // Remove references to fModel in case the fModel is being deleted.
-   // Deactivate attribute frames if they point to obj.
+   // Call SetModel in class editors.
 
+   TGFrameElement *el;
 
-   if ((fModel != obj) || (obj == fCanvas)) return;
-   if (obj == fPad)
-      SetModel(fCanvas, fCanvas, kButton1Down);
-   else
-      SetModel(fPad, fPad, kButton1Down);
+   // Call SetModel on TGedNameFrames (first in the container list)
+   // and map extra-tabs.
+   TIter vistabs(&fVisibleTabs);
+   vistabs(); // skip Style tab
+   TGedTabInfo* ti;
+   while ((ti = (TGedTabInfo *) vistabs())) {
+      TIter fr(ti->fContainer->GetList());
+      el = (TGFrameElement*) fr();
+      ((TGedFrame*) el->fFrame)->SetModel(fModel);
+      do {
+         el->fFrame->MapSubwindows();
+         el->fFrame->Layout();
+         el->fFrame->MapWindow();
+      } while((el = (TGFrameElement *) fr()));
+      ti->fContainer->Layout();
+   }
+
+   TIter next(fTabContainer->GetList());
+   while ((el = (TGFrameElement *) next())) {
+      if ((el->fFrame)->InheritsFrom(TGedFrame::Class())) {
+         el->fFrame->MapSubwindows();
+         ((TGedFrame *)(el->fFrame))->SetModel(fModel);
+         el->fFrame->Layout();
+         el->fFrame->MapWindow();
+      }
+   }
+   fTabContainer->Layout();
+}
+
+//______________________________________________________________________________
+void TGedEditor::PrintFrameStat()
+{
+   // Print contents of fFrameMap.
+
+   printf("TGedEditor::PrintFrameStat()\n");
+   Int_t sum = 0;
+   TIter next(fFrameMap.GetTable());
+   TPair* pair;
+   while ((pair = (TPair*) next())) {
+      if (pair->Value() != 0) {
+         TClass* cl  = (TClass*) pair->Key();
+         printf("TGedFrame created for %s \n", cl->GetName());
+         sum ++;
+      }
+   }
+   printf("SUMMARY: %d editors stored in the local map.\n", sum);
 }