From da57a35fad35265dabc0e4bf537f97d4b99e54f9 Mon Sep 17 00:00:00 2001
From: Matevz Tadel <matevz.tadel@cern.ch>
Date: Mon, 1 Dec 2008 17:35:55 +0000
Subject: [PATCH] Merge the following releases from the fireworks branch:

26432
 - Added TGLSAViewer::DeleteMenuBar().

26444
 - TGLSAViewer - use a steering flag for menu-bar destruction.

26468
 - TEveCaloDataVec - option to define XY axis from cells themselves.

26481
 - TEveCaloDataVec - bugfix;
 - show the new feature in cms_calo*.C tutorials.

26523
 - TEveWindow - new classes for management of EVE vindows;

26524
 - missing include.

26557
 - TEveWindow:
   - support hiding of title-bar directly from frame; render decollapse box
     when hidden;
   - bind context menu to Action/IconBox button;
   - consistent usage of simple frame-style.


git-svn-id: http://root.cern.ch/svn/root/trunk@26561 27541ba8-7e3a-0410-8455-c3a389f83636
---
 graf3d/eve/inc/LinkDef.h            |  11 +-
 graf3d/eve/inc/TEveCaloData.h       |   1 +
 graf3d/eve/inc/TEveManager.h        |   2 +
 graf3d/eve/inc/TEveWindow.h         | 305 +++++++++++
 graf3d/eve/inc/TEveWindowEditor.h   |  47 ++
 graf3d/eve/src/TEveBrowser.cxx      |  76 ++-
 graf3d/eve/src/TEveCaloData.cxx     |  88 ++-
 graf3d/eve/src/TEveElement.cxx      |  17 +-
 graf3d/eve/src/TEveManager.cxx      |  11 +
 graf3d/eve/src/TEveWindow.cxx       | 799 ++++++++++++++++++++++++++++
 graf3d/eve/src/TEveWindowEditor.cxx |  68 +++
 graf3d/gl/inc/TGLSAViewer.h         |   8 +-
 graf3d/gl/src/TGLSAViewer.cxx       |  16 +-
 tutorials/eve/cms_calo.C            |   3 +-
 tutorials/eve/cms_calo_detail.C     |   9 +-
 tutorials/eve/test_windows.C        |  36 ++
 16 files changed, 1446 insertions(+), 51 deletions(-)
 create mode 100644 graf3d/eve/inc/TEveWindow.h
 create mode 100644 graf3d/eve/inc/TEveWindowEditor.h
 create mode 100644 graf3d/eve/src/TEveWindow.cxx
 create mode 100644 graf3d/eve/src/TEveWindowEditor.cxx
 create mode 100644 tutorials/eve/test_windows.C

diff --git a/graf3d/eve/inc/LinkDef.h b/graf3d/eve/inc/LinkDef.h
index 8f550e5c3f6..36476425a93 100644
--- a/graf3d/eve/inc/LinkDef.h
+++ b/graf3d/eve/inc/LinkDef.h
@@ -114,10 +114,19 @@
 // TEvePad
 #pragma link C++ class TEvePad+;
 
-// TEveBrowser
+// TEveBrowser, TEveCompositeFrame, TEveWindow
 #pragma link C++ class TEveListTreeItem+;
 #pragma link C++ class TEveGListTreeEditorFrame+;
 #pragma link C++ class TEveBrowser+;
+#pragma link C++ class TEveCompositeFrame+;
+#pragma link C++ class TEveCompositeFrameInPack+;
+#pragma link C++ class TEveCompositeFrameInTab+;
+#pragma link C++ class TEveWindow+;
+#pragma link C++ class TEveWindowEditor+;
+#pragma link C++ class TEveWindowSlot+;
+#pragma link C++ class TEveWindowMainFrame+;
+#pragma link C++ class TEveWindowPack+;
+#pragma link C++ class TEveWindowTab+;
 
 // TEveGedEditor
 #pragma link C++ class TEveGedEditor+;
diff --git a/graf3d/eve/inc/TEveCaloData.h b/graf3d/eve/inc/TEveCaloData.h
index 2e2315c867a..73e7ca42aec 100644
--- a/graf3d/eve/inc/TEveCaloData.h
+++ b/graf3d/eve/inc/TEveCaloData.h
@@ -241,6 +241,7 @@ public:
    virtual void GetPhiLimits(Double_t &min, Double_t &max) const { min=fPhiMin; max=fPhiMax;}
 
    virtual void  DataChanged();
+   void          SetAxisFromBins(Double_t epsX=0.001, Double_t epsY=0.001);
 
    ClassDef(TEveCaloDataVec, 0); // Manages calorimeter event data.
 };
diff --git a/graf3d/eve/inc/TEveManager.h b/graf3d/eve/inc/TEveManager.h
index df760e5b85b..7b249ebd532 100644
--- a/graf3d/eve/inc/TEveManager.h
+++ b/graf3d/eve/inc/TEveManager.h
@@ -92,6 +92,7 @@ private:
 
    TFolder                  *fMacroFolder;
 
+   TEveElementList          *fWindows;
    TEveViewerList           *fViewers;
    TEveSceneList            *fScenes;
 
@@ -138,6 +139,7 @@ public:
    TEveGedEditor*    GetEditor()    const { return fEditor;    }
    TGStatusBar*      GetStatusBar() const { return fStatusBar; }
 
+   TEveElementList*  GetWindows()  const { return fWindows; }
    TEveSceneList*    GetScenes()   const { return fScenes;  }
    TEveViewerList*   GetViewers()  const { return fViewers; }
 
diff --git a/graf3d/eve/inc/TEveWindow.h b/graf3d/eve/inc/TEveWindow.h
new file mode 100644
index 00000000000..25007438230
--- /dev/null
+++ b/graf3d/eve/inc/TEveWindow.h
@@ -0,0 +1,305 @@
+// @(#)root/eve:$Id$
+// Author: Matevz Tadel 2007
+
+/*************************************************************************
+ * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
+ * All rights reserved.                                                  *
+ *                                                                       *
+ * For the licensing terms see $ROOTSYS/LICENSE.                         *
+ * For the list of contributors see $ROOTSYS/README/CREDITS.             *
+ *************************************************************************/
+
+#ifndef ROOT_TEveWindow
+#define ROOT_TEveWindow
+
+#include "TEveElement.h"
+
+#include "TGFrame.h"
+
+class TEveWindow;
+class TEveWindowSlot;
+class TEveWindowMainFrame;
+class TEveWindowPack;
+class TEveWindowTab;
+
+class TContextMenu;
+
+class TGButton;
+class TGSplitButton;
+class TGTextButton;
+
+class TGPack;
+class TGTab;
+
+//==============================================================================
+// TEveCompositeFrame
+//==============================================================================
+
+class TEveCompositeFrame : public TGCompositeFrame
+{
+   friend class TEveWindow;
+
+private:
+   TEveCompositeFrame(const TEveCompositeFrame&);            // Not implemented
+   TEveCompositeFrame& operator=(const TEveCompositeFrame&); // Not implemented
+
+protected:
+   TGCompositeFrame  *fTopFrame;
+   TGTextButton      *fToggleBar;
+   TGTextButton      *fTitleBar;
+   TGTextButton      *fIconBar;
+   TGLayoutHints     *fEveWindowLH;
+
+   TGButton          *fMiniBar;
+
+   TEveWindow        *fEveParentWindow;
+   TEveWindow        *fEveWindow;
+
+   static TContextMenu *fgCtxMenu;
+
+public:
+   TEveCompositeFrame(TGCompositeFrame* gui_parent, TEveWindow* eve_parent);
+   virtual ~TEveCompositeFrame();
+
+   virtual void Destroy();
+
+   virtual void        AcquireEveWindow(TEveWindow* ew);
+   virtual TEveWindow* RelinquishEveWindow();
+
+   virtual TEveWindow* ChangeEveWindow(TEveWindow* ew);
+
+   virtual void SetCurrent(Bool_t curr);
+   virtual void SetShowTitleBar(Bool_t show);
+
+   void ActionPressed();
+   void FlipTitleBarState();
+   void TitleBarClicked();
+
+   ClassDef(TEveCompositeFrame, 0); // Short description.
+};
+
+
+//==============================================================================
+// TEveCompositeFrameInPack
+//==============================================================================
+
+class TEveCompositeFrameInPack : public TEveCompositeFrame
+{
+private:
+   TEveCompositeFrameInPack(const TEveCompositeFrameInPack&);            // Not implemented
+   TEveCompositeFrameInPack& operator=(const TEveCompositeFrameInPack&); // Not implemented
+
+protected:
+   TGPack        *fPack;
+
+public:
+   TEveCompositeFrameInPack(TGCompositeFrame* parent, TEveWindow* eve_parent,
+                            TGPack* pack);
+   virtual ~TEveCompositeFrameInPack();
+
+   virtual void Destroy();
+
+   ClassDef(TEveCompositeFrameInPack, 0); // Short description.
+};
+
+
+//==============================================================================
+// TEveCompositeFrameInTab
+//==============================================================================
+
+class TEveCompositeFrameInTab : public TEveCompositeFrame
+{
+private:
+   TEveCompositeFrameInTab(const TEveCompositeFrameInTab&);            // Not implemented
+   TEveCompositeFrameInTab& operator=(const TEveCompositeFrameInTab&); // Not implemented
+
+protected:
+   TGTab            *fTab;
+   TGCompositeFrame *fParentInTab;
+
+   Int_t FindTabIndex();
+
+public:
+   TEveCompositeFrameInTab(TGCompositeFrame* parent, TEveWindow* eve_parent,
+                           TGTab* tab);
+   virtual ~TEveCompositeFrameInTab();
+
+   virtual void Destroy();
+
+   virtual void        AcquireEveWindow(TEveWindow* ew);
+   virtual TEveWindow* RelinquishEveWindow();
+
+   virtual void SetCurrent(Bool_t curr);
+
+   ClassDef(TEveCompositeFrameInTab, 0); // Short description.
+};
+
+
+//==============================================================================
+//==============================================================================
+// TEveWindow classes
+//==============================================================================
+//==============================================================================
+
+
+//==============================================================================
+// TEveWindow
+//==============================================================================
+
+class TEveWindow : public TEveElementList
+{
+private:
+   TEveWindow(const TEveWindow&);            // Not implemented
+   TEveWindow& operator=(const TEveWindow&); // Not implemented
+
+protected:
+   TEveCompositeFrame  *fEveFrame;
+   Bool_t               fShowTitleBar;
+
+   static TEveWindow   *fgCurrentWindow;
+
+public:
+   TEveWindow(const Text_t* n="TEveWindow", const Text_t* t="");
+   virtual ~TEveWindow();
+
+   void SwapWindow(TEveWindow* w);
+   void SwapWindowWithCurrent();        // *MENU*
+
+   virtual void DestroyWindow();        // *MENU*
+   virtual void DestroyWindowAndSlot(); // *MENU*
+
+   virtual TGFrame*            GetGUIFrame() { return 0; } // XXXX should be abstract
+
+   TEveCompositeFrame* GetEveFrame()  { return fEveFrame; }
+   void                ClearEveFrame();
+
+   void   PopulateSlot(TEveCompositeFrame* ef); 
+
+   void   FlipShowTitleBar()      { SetShowTitleBar(!fShowTitleBar); }
+   Bool_t GetShowTitleBar() const { return fShowTitleBar; }
+   void   SetShowTitleBar(Bool_t x);
+
+   Bool_t       IsCurrent() const { return fgCurrentWindow == this; }
+   virtual void SetCurrent(Bool_t curr);
+
+   void TitleBarClicked();
+
+   // Static helper functions for common window management scenarios.
+
+   static TEveWindowSlot* CreateDefaultWindowSlot();
+   static TEveWindowSlot* CreateWindowInTab(TGTab* tab, TEveWindow* eve_parent=0);
+
+   static Pixel_t fgCurrentBackgroundColor;
+   static Pixel_t fgMiniBarBackgroundColor;
+
+   ClassDef(TEveWindow, 0); // Short description.
+};
+
+
+//==============================================================================
+// TEveWindowSlot
+//==============================================================================
+
+class TEveWindowSlot : public TEveWindow
+{
+private:
+   TEveWindowSlot(const TEveWindowSlot&);            // Not implemented
+   TEveWindowSlot& operator=(const TEveWindowSlot&); // Not implemented
+
+protected:
+   TGTextButton      *fEmptyButt;
+
+public:
+   TEveWindowSlot(const Text_t* n="TEveWindowSlot", const Text_t* t="");
+   virtual ~TEveWindowSlot();
+
+   virtual TGFrame* GetGUIFrame();
+
+   virtual void SetCurrent(Bool_t curr);
+
+   TEveWindowPack* MakePack(); // *MENU*
+   TEveWindowTab*  MakeTab();  // *MENU*
+
+   ClassDef(TEveWindowSlot, 0); // Short description.
+};
+
+
+//==============================================================================
+// TEveWindowMainFrame
+//==============================================================================
+
+class TEveWindowMainFrame : public TEveWindow
+{
+private:
+   TEveWindowMainFrame(const TEveWindowMainFrame&);            // Not implemented
+   TEveWindowMainFrame& operator=(const TEveWindowMainFrame&); // Not implemented
+
+protected:
+   TGMainFrame         *fMainFrame;
+
+public:
+   TEveWindowMainFrame(const Text_t* n="TEveWindowMainFrame", const Text_t* t="");
+   virtual ~TEveWindowMainFrame() {}
+
+   virtual TGFrame* GetGUIFrame();
+
+   ClassDef(TEveWindowMainFrame, 0); // Short description.
+};
+
+
+//==============================================================================
+// TEveWindowPack
+//==============================================================================
+
+class TEveWindowPack : public TEveWindow // , public TGPack
+{
+private:
+   TEveWindowPack(const TEveWindowPack&);            // Not implemented
+   TEveWindowPack& operator=(const TEveWindowPack&); // Not implemented
+
+protected:
+   TGPack              *fPack;
+
+public:
+   TEveWindowPack(TGPack* p, const Text_t* n="TEveWindowPack", const Text_t* t="");
+   virtual ~TEveWindowPack();
+
+   virtual TGFrame* GetGUIFrame();
+
+   TGPack* GetPack() const { return fPack; }
+
+   TEveWindowSlot* NewSlot(); // *MENU*
+
+   void FlipOrientation(); // *MENU*
+
+   ClassDef(TEveWindowPack, 0); // Short description.
+};
+
+
+//==============================================================================
+// TEveWindowTab
+//==============================================================================
+
+class TEveWindowTab : public TEveWindow
+{
+private:
+   TEveWindowTab(const TEveWindowTab&);            // Not implemented
+   TEveWindowTab& operator=(const TEveWindowTab&); // Not implemented
+
+protected:
+   TGTab               *fTab;
+
+public:
+   TEveWindowTab(TGTab* tab, const Text_t* n="TEveWindowTab", const Text_t* t="");
+   virtual ~TEveWindowTab() {}
+
+   virtual TGFrame* GetGUIFrame();
+
+   TGTab* GetTab() const { return fTab; }
+
+   TEveWindowSlot* NewSlot(); // *MENU*
+
+   ClassDef(TEveWindowTab, 0); // Short description.
+};
+
+#endif
diff --git a/graf3d/eve/inc/TEveWindowEditor.h b/graf3d/eve/inc/TEveWindowEditor.h
new file mode 100644
index 00000000000..7df10f73701
--- /dev/null
+++ b/graf3d/eve/inc/TEveWindowEditor.h
@@ -0,0 +1,47 @@
+// @(#)root/eve:$Id$
+// Author: Matevz Tadel 2007
+
+/*************************************************************************
+ * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
+ * All rights reserved.                                                  *
+ *                                                                       *
+ * For the licensing terms see $ROOTSYS/LICENSE.                         *
+ * For the list of contributors see $ROOTSYS/README/CREDITS.             *
+ *************************************************************************/
+
+#ifndef ROOT_TEveWindowEditor
+#define ROOT_TEveWindowEditor
+
+#include "TGedFrame.h"
+
+class TGButton;
+class TGCheckButton;
+class TGNumberEntry;
+class TGColorSelect;
+
+class TEveWindow;
+
+class TEveWindowEditor : public TGedFrame
+{
+private:
+   TEveWindowEditor(const TEveWindowEditor&);            // Not implemented
+   TEveWindowEditor& operator=(const TEveWindowEditor&); // Not implemented
+
+protected:
+   TEveWindow            *fM; // Model object.
+
+   TGCheckButton         *fShowTitleBar;
+
+public:
+   TEveWindowEditor(const TGWindow* p=0, Int_t width=170, Int_t height=30,
+         UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground());
+   virtual ~TEveWindowEditor() {}
+
+   virtual void SetModel(TObject* obj);
+
+   void DoShowTitleBar();
+
+   ClassDef(TEveWindowEditor, 0); // GUI editor for TEveWindow.
+};
+
+#endif
diff --git a/graf3d/eve/src/TEveBrowser.cxx b/graf3d/eve/src/TEveBrowser.cxx
index c476675a191..b7abbef52bc 100644
--- a/graf3d/eve/src/TEveBrowser.cxx
+++ b/graf3d/eve/src/TEveBrowser.cxx
@@ -16,6 +16,7 @@
 #include "TEveManager.h"
 #include "TEveSelection.h"
 #include "TEveGedEditor.h"
+#include "TEveWindow.h"
 
 #include "TGFileBrowser.h"
 #include "TBrowser.h"
@@ -261,6 +262,8 @@ void TEveGListTreeEditorFrame::ReconfToHorizontal()
    {
       if (el->fFrame == fSplitter)
       {
+         // This is needed so that splitter window gets destroyed on server.
+         fSplitter->ReparentWindow(fClient->GetDefaultRoot());
          delete fSplitter;
          el->fFrame = fSplitter = new TGVSplitter(fFrame);
          el->fLayout->SetLayoutHints(kLHintsLeft | kLHintsExpandY);
@@ -304,6 +307,8 @@ void TEveGListTreeEditorFrame::ReconfToVertical()
    {
       if (el->fFrame == fSplitter)
       {
+         // This is needed so that splitter window gets destroyed on server.
+         fSplitter->ReparentWindow(fClient->GetDefaultRoot());
          delete fSplitter;
          el->fFrame = fSplitter = new TGHSplitter(fFrame);
          el->fLayout->SetLayoutHints(kLHintsTop | kLHintsExpandX);
@@ -522,6 +527,7 @@ void TEveBrowser::CalculateReparentXY(TGObject* parent, Int_t& x, Int_t& y)
 namespace
 {
 enum EEveMenu_e {
+   kNewMainFrameSlot, kNewTabSlot,
    kNewViewer,  kNewScene,  kNewProjector,
    kNewBrowser, kNewCanvas, kNewCanvasExt, kNewTextEditor, kNewHtmlBrowser,
    kVerticalBrowser,
@@ -546,14 +552,17 @@ TEveBrowser::TEveBrowser(UInt_t w, UInt_t h) :
    // Construct Eve menu.
 
    fEvePopup = new TGPopupMenu(gClient->GetRoot());
-   fEvePopup->AddEntry("New &Viewer",      kNewViewer);
-   fEvePopup->AddEntry("New &Scene",       kNewScene);
-   fEvePopup->AddEntry("New &Projector",   kNewProjector);
+   // fEvePopup->AddEntry("New &MainFrame Slot", kNewMainFrameSlot);
+   fEvePopup->AddEntry("New &Tab Slot",       kNewTabSlot);
    fEvePopup->AddSeparator();
-   fEvePopup->AddEntry("New &Browser",     kNewBrowser);
-   fEvePopup->AddEntry("New &Canvas",      kNewCanvas);
-   fEvePopup->AddEntry("New Canvas Ext",   kNewCanvasExt);
-   fEvePopup->AddEntry("New Text Editor",  kNewTextEditor);
+   fEvePopup->AddEntry("New &Viewer",         kNewViewer);
+   fEvePopup->AddEntry("New &Scene",          kNewScene);
+   fEvePopup->AddEntry("New &Projector",      kNewProjector);
+   fEvePopup->AddSeparator();
+   fEvePopup->AddEntry("New &Browser",        kNewBrowser);
+   fEvePopup->AddEntry("New &Canvas",         kNewCanvas);
+   fEvePopup->AddEntry("New Canvas Ext",      kNewCanvasExt);
+   fEvePopup->AddEntry("New Text &Editor",    kNewTextEditor);
    // fEvePopup->AddEntry("New HTML Browser", kNewHtmlBrowser);
    fEvePopup->AddSeparator();
 
@@ -608,43 +617,52 @@ void TEveBrowser::EveMenu(Int_t id)
 
    switch (id)
    {
-      case kNewViewer:
+      case kNewMainFrameSlot: {
+         // XXXX
+         break;
+      }
+      case kNewTabSlot: {
+         TEveWindowSlot* ew_slot = TEveWindow::CreateWindowInTab(GetTabRight(), 0);
+         ew_slot->SetCurrent(kTRUE);
+         break;
+      }
+      case kNewViewer: {
          gEve->SpawnNewViewer("Viewer Pepe");
          break;
-
-      case kNewScene:
+      }
+      case kNewScene: {
          gEve->SpawnNewScene("Scena Mica");
          break;
-
+      }
       case kNewProjector: {
          TEveElement* pr = (TEveElement*) (gROOT->GetClass("TEveProjectionManager")->New());
          pr->SetElementNameTitle("Projector", "User-created projector.");
          gEve->AddToListTree(pr, kTRUE);
          break;
       }
-      case kNewBrowser:
+      case kNewBrowser: {
          gROOT->ProcessLineFast("new TBrowser");
          break;
-
-      case kNewCanvas:
+      }
+      case kNewCanvas: {
          StartEmbedding(1);
          gROOT->ProcessLineFast("new TCanvas");
          StopEmbedding();
          SetTabTitle("Canvas", 1);
          break;
-
-      case kNewCanvasExt:
+      }
+      case kNewCanvasExt: {
          gROOT->ProcessLineFast("new TCanvas");
          break;
-
-      case kNewTextEditor:
+      }
+      case kNewTextEditor: {
          StartEmbedding(1);
          gROOT->ProcessLineFast(Form("new TGTextEditor((const char *)0, (const TGWindow *)0x%lx)", gClient->GetRoot()));
          StopEmbedding();
          SetTabTitle("Editor", 1);
          break;
-
-      case kNewHtmlBrowser:
+      }
+      case kNewHtmlBrowser: {
          gSystem->Load("libGuiHtml");
          if (gSystem->Load("libRHtml") >= 0)
          {
@@ -655,30 +673,30 @@ void TEveBrowser::EveMenu(Int_t id)
             SetTabTitle("HTML", 1);
          }
          break;
-
+      }
       case kSel_PS_Ignore:
       case kSel_PS_Element:
       case kSel_PS_Projectable:
       case kSel_PS_Compound:
       case kSel_PS_PableCompound:
-      case kSel_PS_Master:
+      case kSel_PS_Master: {
          gEve->GetSelection()->SetPickToSelect(id - kSel_PS_Ignore);
          fSelPopup->RCheckEntry(kSel_PS_Ignore + gEve->GetSelection()->GetPickToSelect(),
                                 kSel_PS_Ignore, kSel_PS_END - 1);
          break;
-
+      }
       case kHil_PS_Ignore:
       case kHil_PS_Element:
       case kHil_PS_Projectable:
       case kHil_PS_Compound:
       case kHil_PS_PableCompound:
-      case kHil_PS_Master:
+      case kHil_PS_Master: {
          gEve->GetHighlight()->SetPickToSelect(id - kHil_PS_Ignore);
          fHilPopup->RCheckEntry(kHil_PS_Ignore + gEve->GetHighlight()->GetPickToSelect(),
                                 kHil_PS_Ignore, kHil_PS_END - 1);
          break;
-
-      case kVerticalBrowser:
+      }
+      case kVerticalBrowser: {
          if (fEvePopup->IsEntryChecked(kVerticalBrowser)) {
             gEve->GetLTEFrame()->ReconfToHorizontal();
             fEvePopup->UnCheckEntry(kVerticalBrowser);
@@ -687,11 +705,11 @@ void TEveBrowser::EveMenu(Int_t id)
             fEvePopup->CheckEntry(kVerticalBrowser);
          }
          break;
+      }
 
-
-
-      default:
+      default: {
          break;
+      }
    }
 }
 
diff --git a/graf3d/eve/src/TEveCaloData.cxx b/graf3d/eve/src/TEveCaloData.cxx
index bf21a0cef9f..4353149eb81 100644
--- a/graf3d/eve/src/TEveCaloData.cxx
+++ b/graf3d/eve/src/TEveCaloData.cxx
@@ -19,6 +19,7 @@
 #include "TList.h"
 
 #include <cassert>
+#include <algorithm>
 
 
 
@@ -201,7 +202,7 @@ void TEveCaloData::CellGeom_t::Configure(Float_t etaMin, Float_t etaMax, Float_t
 
 //______________________________________________________________________________
 //
-// Blabla.
+// Calo data for universal cell geometry. 
 
 ClassImp(TEveCaloDataVec);
 
@@ -331,6 +332,8 @@ void TEveCaloDataVec::GetCellList(Float_t eta, Float_t etaD,
 //______________________________________________________________________________
 void TEveCaloDataVec::Rebin(TAxis* ax, TAxis* ay, vCellId_t &ids, Bool_t et, RebinData_t& rdata) const
 {
+   // Rebin cells.
+
    rdata.fNSlices = GetNSlices();
    rdata.fBinData.assign((ax->GetNbins()+2)*(ay->GetNbins()+2), -1);
 
@@ -407,6 +410,89 @@ void TEveCaloDataVec::DataChanged()
 }
 
 
+//______________________________________________________________________________
+void  TEveCaloDataVec::SetAxisFromBins(Double_t epsX, Double_t epsY)
+{
+   // Set XY axis from cells geometry.
+
+   std::vector<Double_t> binX;
+   std::vector<Double_t> binY;
+
+   for(vCellGeom_ci i=fGeomVec.begin(); i!=fGeomVec.end(); i++)
+   {
+      const CellGeom_t &ch = *i;
+
+      binX.push_back(ch.EtaMin());
+      binX.push_back(ch.EtaMax());
+      binY.push_back(ch.PhiMin());
+      binY.push_back(ch.PhiMax());
+   }
+
+   std::sort(binX.begin(), binX.end());
+   std::sort(binY.begin(), binY.end());
+
+   Int_t cnt = 0;
+   Double_t sum = 0;
+   Double_t val;
+
+   // X axis
+   Double_t dx = binX.back() - binX.front();
+   epsX *= dx;
+   std::vector<Double_t> newX;
+   newX.push_back(binX.front()); // underflow
+   Int_t nX = binX.size()-1;
+   for(Int_t i=0; i<nX; i++) 
+   { 
+      val = (sum +binX[i])/(cnt+1);
+      if (binX[i+1] -val > epsX)
+      {
+         newX.push_back(val);
+         cnt = 0;
+         sum = 0;
+      }
+      else 
+      {
+         sum += binX[i];
+         cnt++;
+      }
+   }
+   newX.push_back(binX.back()); // overflow
+
+   // Y axis
+   cnt = 0;
+   sum = 0;
+   std::vector<Double_t> newY;
+   Double_t dy = binY.back() - binY.front();
+   epsY *= dy;
+   newY.push_back(binY.front());// underflow
+   Int_t nY = binY.size()-1;
+   for(Int_t i=0 ; i<nY; i++) 
+   {
+      val = (sum +binY[i])/(cnt+1);
+      if (binY[i+1] -val > epsY )
+      {
+         newY.push_back(val);
+         cnt = 0;
+         sum = 0;
+      }
+      else 
+      {
+         sum += binY[i];
+         cnt++;
+      }
+
+   }
+   newY.push_back(binY.back()); // overflow
+
+   if (fEtaAxis) delete fEtaAxis;
+   if (fPhiAxis) delete fPhiAxis;
+
+   fEtaAxis = new TAxis(newX.size()-1, &newX[0]);
+   fPhiAxis = new TAxis(newY.size()-1, &newY[0]);
+   fEtaAxis->SetNdivisions(510);
+   fPhiAxis->SetNdivisions(510);
+}
+
 //==============================================================================
 // TEveCaloDataHist
 //==============================================================================
diff --git a/graf3d/eve/src/TEveElement.cxx b/graf3d/eve/src/TEveElement.cxx
index 3335e404dad..792565f7560 100644
--- a/graf3d/eve/src/TEveElement.cxx
+++ b/graf3d/eve/src/TEveElement.cxx
@@ -1378,7 +1378,8 @@ void TEveElement::Destroy()
    static const TEveException eh("TEveElement::Destroy ");
 
    if (fDenyDestroy > 0)
-      throw(eh + "this element '%s' is protected against destruction.", GetElementName());
+      throw eh + TString::Format("element '%s' (%s*) 0x%lx is protected against destruction.",
+                                 GetElementName(), IsA()->GetName(), this);
 
    gEve->PreDeleteElement(this);
    delete this;
@@ -1392,12 +1393,14 @@ void TEveElement::DestroyOrWarn()
 
    static const TEveException eh("TEveElement::DestroyOrWarn ");
 
-   if (fDenyDestroy > 0)
-      throw(eh + "this element '%s' is protected against destruction.", GetElementName());
-
-   gEve->PreDeleteElement(this);
-   delete this;
-   gEve->Redraw3D();
+   try
+   {
+      Destroy();
+   }
+   catch (TEveException& exc)
+   {
+      Warning(eh, exc);
+   }
 }
 
 //______________________________________________________________________________
diff --git a/graf3d/eve/src/TEveManager.cxx b/graf3d/eve/src/TEveManager.cxx
index 624047639a6..347c7c440fc 100644
--- a/graf3d/eve/src/TEveManager.cxx
+++ b/graf3d/eve/src/TEveManager.cxx
@@ -68,6 +68,7 @@ TEveManager::TEveManager(UInt_t w, UInt_t h, Bool_t map_window, Option_t* opt) :
 
    fMacroFolder (0),
 
+   fWindows        (0),
    fViewers        (0),
    fScenes         (0),
    fViewer         (0),
@@ -123,6 +124,8 @@ TEveManager::TEveManager(UInt_t w, UInt_t h, Bool_t map_window, Option_t* opt) :
    gROOT->GetListOfBrowsables()->Add(fMacroFolder);
 
 
+   fWindows = new TEveElementList("Windows", "List of EVE windows");
+
    // Build GUI
    fBrowser   = new TEveBrowser(w, h);
    fStatusBar = fBrowser->GetStatusBar();
@@ -152,6 +155,9 @@ TEveManager::TEveManager(UInt_t w, UInt_t h, Bool_t map_window, Option_t* opt) :
 
    // --------------------------------
 
+   fWindows->IncDenyDestroy();
+   AddToListTree(fWindows, kTRUE);
+
    fViewers = new TEveViewerList("Viewers");
    fViewers->IncDenyDestroy();
    AddToListTree(fViewers, kTRUE);
@@ -204,6 +210,11 @@ TEveManager::~TEveManager()
    fViewers->Destroy();
    fViewers = 0;
 
+   fWindows->DestroyElements();
+   fWindows->DecDenyDestroy();
+   fWindows->Destroy();
+   fWindows = 0;
+
    fOrphanage->DecDenyDestroy();
    fHighlight->DecDenyDestroy();
    fSelection->DecDenyDestroy();
diff --git a/graf3d/eve/src/TEveWindow.cxx b/graf3d/eve/src/TEveWindow.cxx
new file mode 100644
index 00000000000..561d3ea16f9
--- /dev/null
+++ b/graf3d/eve/src/TEveWindow.cxx
@@ -0,0 +1,799 @@
+// @(#)root/eve:$Id$
+// Author: Matevz Tadel 2007
+
+/*************************************************************************
+ * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
+ * All rights reserved.                                                  *
+ *                                                                       *
+ * For the licensing terms see $ROOTSYS/LICENSE.                         *
+ * For the list of contributors see $ROOTSYS/README/CREDITS.             *
+ *************************************************************************/
+
+#include "TEveWindow.h"
+#include "TEveManager.h"
+#include "TEveSelection.h"
+
+#include "TContextMenu.h"
+
+#include "TGButton.h"
+#include "TContextMenu.h"
+#include "TGMenu.h"
+#include "TGPack.h"
+#include "TGTab.h"
+
+#include <cassert>
+
+//==============================================================================
+//==============================================================================
+// CompositeFrame classes - slots for TEveWindows
+//==============================================================================
+//==============================================================================
+
+
+//==============================================================================
+// TEveCompositeFrame
+//==============================================================================
+
+//______________________________________________________________________________
+// 
+// Base-class for EVE window slots.
+//
+
+ClassImp(TEveCompositeFrame);
+
+TContextMenu* TEveCompositeFrame::fgCtxMenu = 0;
+
+//______________________________________________________________________________
+TEveCompositeFrame::TEveCompositeFrame(TGCompositeFrame* parent,
+                                       TEveWindow*   eve_parent) :
+   TGCompositeFrame (parent, 0, 0, kVerticalFrame),
+
+   fTopFrame    (0),
+   fToggleBar   (0),
+   fTitleBar    (0),
+   fIconBar     (0),
+   fEveWindowLH (0),
+
+   fMiniBar     (0),
+
+   fEveParentWindow (eve_parent),
+   fEveWindow       (0)
+{
+   // Constructor.
+
+   static const UInt_t topH = 14, miniH = 4;
+
+   // --- TopFrame
+
+   fTopFrame = new TGHorizontalFrame(this, 20, topH);
+
+   fToggleBar = new TGTextButton(fTopFrame, "Hide");
+   fToggleBar->ChangeOptions(kRaisedFrame);
+   fToggleBar->Resize(40, topH);
+   fTopFrame->AddFrame(fToggleBar, new TGLayoutHints(kLHintsNormal, 0,0,0,0));//1,1,1,1));
+
+   fTitleBar = new TGTextButton(fTopFrame, "Title Bar");
+   fTitleBar->ChangeOptions(kRaisedFrame);
+   fTitleBar->Resize(40, topH);
+   fTopFrame->AddFrame(fTitleBar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX,  0,0,0,0));//1,1,1,1));
+
+   fIconBar = new TGTextButton(fTopFrame, "Actions");
+   fIconBar->ChangeOptions(kRaisedFrame);
+   fIconBar->Resize(40, topH);
+   fTopFrame->AddFrame(fIconBar, new TGLayoutHints(kLHintsNormal,  0,0,0,0));//1,1,1,1));
+
+   AddFrame(fTopFrame, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
+
+   fToggleBar->Connect("Clicked()", "TEveCompositeFrame", this, "FlipTitleBarState()");
+   fTitleBar ->Connect("Clicked()", "TEveCompositeFrame", this, "TitleBarClicked()");
+   fIconBar  ->Connect("Pressed()", "TEveCompositeFrame", this, "ActionPressed()");
+
+   // --- MiniBar
+
+   fMiniBar = new TGButton(this);
+   fMiniBar->ChangeOptions(kRaisedFrame | kFixedHeight);
+   fMiniBar->Resize(20, miniH);
+   fMiniBar->SetBackgroundColor(TEveWindow::fgMiniBarBackgroundColor);
+   AddFrame(fMiniBar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
+
+   fMiniBar->Connect("Clicked()", "TEveCompositeFrame", this, "FlipTitleBarState()");
+
+   // --- Common settings.
+
+   SetCleanup(kDeepCleanup);
+
+   MapSubwindows();
+   HideFrame(fMiniBar);
+
+   // Layout for embedded windows.
+   fEveWindowLH = new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY);
+}
+
+//______________________________________________________________________________
+TEveCompositeFrame::~TEveCompositeFrame()
+{
+   // If fEveWindow != 0 we are being deleted from the ROOT GUI side.
+   // Relinquishe EveWindow and ref-counting should do the rest.
+
+   if (fEveWindow != 0)
+   {
+      printf("TEveCompositeFrame::~TEveCompositeFrame - EveWindow not null '%s'.\n",
+             fEveWindow->GetElementName());
+      fEveWindow->ClearEveFrame();
+      RelinquishEveWindow();
+   }
+
+   delete fEveWindowLH;
+}
+
+//______________________________________________________________________________
+void TEveCompositeFrame::Destroy()
+{
+   // Virtual function called from eve side when the frame should be
+   // destroyed. This means we expect that fEveWindow is null.
+   //
+   // See implementations in TEveCompositeFrameInPack and
+   // TEveCompositeFrameInTab.
+}
+
+//==============================================================================
+
+void TEveCompositeFrame::ActionPressed()
+{
+   if (fgCtxMenu == 0) {
+      fgCtxMenu = new TContextMenu("", "");
+   }
+
+   Int_t    x, y;
+   UInt_t   w, h;
+   Window_t childdum;
+   gVirtualX->GetWindowSize(fIconBar->GetId(), x, y, w, h);
+   gVirtualX->TranslateCoordinates(fIconBar->GetId(),
+                                   gClient->GetDefaultRoot()->GetId(),
+                                   0, 0, x, y, childdum);
+
+   fgCtxMenu->Popup(x - 2, y + h - 2, fEveWindow);
+}
+
+//______________________________________________________________________________
+void TEveCompositeFrame::FlipTitleBarState()
+{
+   fEveWindow->FlipShowTitleBar();
+}
+
+//______________________________________________________________________________
+void TEveCompositeFrame::TitleBarClicked()
+{
+   fEveWindow->TitleBarClicked();
+}
+
+//==============================================================================
+
+//______________________________________________________________________________
+void TEveCompositeFrame::AcquireEveWindow(TEveWindow* ew)
+{
+   // Accept window and increase its deny-destroy count.
+   // Window's gui-frame is embedded and mapped.
+   // Layout is not called.
+   //
+   // Throws an exception if a window is already embedded or if 0 is
+   // passed as an argument.
+
+   // Replace current eve-window with the given one.
+   // Current GUI window is unmapped, removed and reparented to default-root.
+   // New GUI window is reparented to this, added and mapped.
+
+   static const TEveException eh("TEveCompositeFrame::AcquireEveWindow ");
+
+   if (fEveWindow)
+      throw eh + "Window already set.";
+
+   if (ew == 0)
+      throw eh + "Called with 0 argument.";
+
+   fEveWindow = ew;
+
+   fEveWindow->IncDenyDestroy();
+   TGFrame* gui_frame = fEveWindow->GetGUIFrame();
+   gui_frame->ReparentWindow(this);
+   AddFrame(gui_frame, fEveWindowLH);
+   gui_frame->MapWindow();
+
+   SetCurrent(fEveWindow->IsCurrent());
+   SetShowTitleBar(fEveWindow->GetShowTitleBar());
+}
+
+//______________________________________________________________________________
+TEveWindow* TEveCompositeFrame::RelinquishEveWindow()
+{
+   // Remove window and decrease its deny-destroy count.
+   // Window's gui-frame is unmapped, removed and reparented to default-root.
+
+   TEveWindow* ex_ew = fEveWindow;
+
+   if (fEveWindow)
+   {
+      TGFrame* gui_frame = fEveWindow->GetGUIFrame();
+      gui_frame->UnmapWindow();
+      RemoveFrame(gui_frame);
+      gui_frame->ReparentWindow(fClient->GetDefaultRoot());
+      fEveWindow->DecDenyDestroy();
+      fEveWindow = 0;
+   }
+
+   return ex_ew;
+}
+
+//______________________________________________________________________________
+TEveWindow* TEveCompositeFrame::ChangeEveWindow(TEveWindow* ew)
+{
+   // Replace current eve-window with the given one.
+   // Current GUI window is unmapped, removed and reparented to default-root.
+   // New GUI window is reparented to this, added and mapped.
+
+   TEveWindow* ex_ew = RelinquishEveWindow();
+
+   AcquireEveWindow(ew);
+
+   return ex_ew;
+}
+
+//______________________________________________________________________________
+void TEveCompositeFrame::SetCurrent(Bool_t curr)
+{
+   if (curr) {
+      fTitleBar->SetBackgroundColor(TEveWindow::fgCurrentBackgroundColor);
+   } else {
+      fTitleBar->SetBackgroundColor(GetDefaultFrameBackground());
+   }
+   fClient->NeedRedraw(fTitleBar);
+}
+
+//______________________________________________________________________________
+void TEveCompositeFrame::SetShowTitleBar(Bool_t show)
+{
+   if (show) {
+      HideFrame(fMiniBar);
+      ShowFrame(fTopFrame);
+   } else {
+      HideFrame(fTopFrame);
+      ShowFrame(fMiniBar);
+   }
+}
+
+
+//==============================================================================
+// TEveCompositeFrameInPack
+//==============================================================================
+
+//______________________________________________________________________________
+//
+// An EVE window-slot contained within one tab of a TGTab.
+
+ClassImp(TEveCompositeFrameInPack);
+
+//______________________________________________________________________________
+TEveCompositeFrameInPack::TEveCompositeFrameInPack(TGCompositeFrame* parent,
+                                                   TEveWindow* eve_parent,
+                                                   TGPack*     pack) :
+   TEveCompositeFrame(parent, eve_parent),
+   fPack (pack)
+{
+   // Constructor.
+}
+
+//______________________________________________________________________________
+TEveCompositeFrameInPack::~TEveCompositeFrameInPack()
+{
+   // Destructor.
+}
+
+//______________________________________________________________________________
+void TEveCompositeFrameInPack::Destroy()
+{
+   printf("TEveCompositeFrameInPack::Destroy()\n");
+
+   assert(fEveWindow == 0);
+
+   fPack->RemoveFrame(this);
+   delete this;
+}
+
+//==============================================================================
+// TEveCompositeFrameInTab
+//==============================================================================
+
+//______________________________________________________________________________
+//
+// An EVE window-slot contained within one tab of a TGTab.
+
+ClassImp(TEveCompositeFrameInTab);
+
+//______________________________________________________________________________
+TEveCompositeFrameInTab::TEveCompositeFrameInTab(TGCompositeFrame* parent,
+                                                 TEveWindow* eve_parent,
+                                                 TGTab*      tab) :
+   TEveCompositeFrame(parent, eve_parent),
+   fTab         (tab),
+   fParentInTab (parent)
+{
+   // Constructor.
+}
+
+//______________________________________________________________________________
+TEveCompositeFrameInTab::~TEveCompositeFrameInTab()
+{
+   // Destructor.
+}
+
+//______________________________________________________________________________
+Int_t TEveCompositeFrameInTab::FindTabIndex()
+{
+   // Return index of this frame in the tab.
+   // Throws an exception if it is not found.
+
+   static const TEveException eh("TEveCompositeFrameInTab::FindTabIndex ");
+
+   Int_t nt = fTab->GetNumberOfTabs();
+   for (Int_t t = 0; t < nt; ++t)
+   {
+      if (fTab->GetTabContainer(t) == fParentInTab)
+      {
+         return t;
+      }
+   }
+
+   throw eh + "parent frame not found in tab.";
+}
+
+//______________________________________________________________________________
+void TEveCompositeFrameInTab::Destroy()
+{
+   printf("TEveCompositeFrameInTab::Destroy()\n");
+
+   assert (fEveWindow == 0);
+
+   Int_t t = FindTabIndex();
+
+   // disconnect form Removed() if / when connected
+   fTab->RemoveTab(t, kFALSE);
+   fParentInTab->DestroyWindow();
+   fParentInTab->SetCleanup(kNoCleanup);
+   delete fParentInTab;
+   delete this;
+}
+
+//______________________________________________________________________________
+void TEveCompositeFrameInTab::AcquireEveWindow(TEveWindow* ew)
+{
+   TEveCompositeFrame::AcquireEveWindow(ew);
+
+   Int_t t = FindTabIndex();
+   fTab->GetTabTab(t)->SetText(new TGString(fEveWindow->GetElementName()));
+   fTab->Layout();
+}
+//______________________________________________________________________________
+TEveWindow* TEveCompositeFrameInTab::RelinquishEveWindow()
+{
+   Int_t t = FindTabIndex();
+   fTab->GetTabTab(t)->SetText(new TGString("<relinquished>"));
+   fTab->Layout();
+
+   return TEveCompositeFrame::RelinquishEveWindow();
+}
+
+//______________________________________________________________________________
+void TEveCompositeFrameInTab::SetCurrent(Bool_t curr)
+{
+   TEveCompositeFrame::SetCurrent(curr);
+
+   Int_t t = FindTabIndex();
+   TGTabElement* te = fTab->GetTabTab(t);
+   if (curr) {
+      te->SetBackgroundColor(TEveWindow::fgCurrentBackgroundColor);
+   } else {
+      te->SetBackgroundColor(GetDefaultFrameBackground());
+   }
+   fClient->NeedRedraw(te);
+}
+
+
+//==============================================================================
+//==============================================================================
+// TEveWindow classes
+//==============================================================================
+//==============================================================================
+
+
+//==============================================================================
+// TEveWindow
+//==============================================================================
+
+//______________________________________________________________________________
+// Description of TEveWindow
+//
+
+ClassImp(TEveWindow);
+
+TEveWindow* TEveWindow::fgCurrentWindow = 0;
+Pixel_t     TEveWindow::fgCurrentBackgroundColor = 0x80A0C0;
+Pixel_t     TEveWindow::fgMiniBarBackgroundColor = 0x80C0A0;
+
+//______________________________________________________________________________
+TEveWindow::TEveWindow(const Text_t* n, const Text_t* t) :
+   TEveElementList(n, t),
+
+   fEveFrame     (0),
+   fShowTitleBar (kTRUE)
+{
+   // Constructor.
+
+   // Override from TEveElementList.
+   fChildClass = TEveWindow::Class();
+}
+
+//______________________________________________________________________________
+TEveWindow::~TEveWindow()
+{
+   if (this == fgCurrentWindow)
+      fgCurrentWindow = 0;
+
+   printf("TEveWindow::~TEveWindow  '%s' '%s', cnt=%d\n", GetElementName(), ClassName(), fDenyDestroy);
+}
+
+//==============================================================================
+
+//______________________________________________________________________________
+void TEveWindow::SwapWindow(TEveWindow* w)
+{
+   printf ("Swapping ... yeah, right :)\n");
+}
+
+//______________________________________________________________________________
+void TEveWindow::SwapWindowWithCurrent()
+{
+   static const TEveException eh("TEveWindow::SwapWindowWithCurrent ");
+
+   if (fgCurrentWindow == 0)
+      throw eh + "Current eve-window is not set.";
+
+   if (fgCurrentWindow == this)
+      throw eh + "This is the current window ... nothing changed.";
+
+   SwapWindow(fgCurrentWindow);
+}
+
+//______________________________________________________________________________
+void TEveWindow::DestroyWindow()
+{
+   printf("TEveWindow::DestroyWindow '%s' '%s', cnt=%d\n", GetElementName(), ClassName(), fDenyDestroy);
+
+   if (fEveFrame != 0 && fDenyDestroy == 1)
+   {
+      TEveWindowSlot* ew_slot = TEveWindow::CreateDefaultWindowSlot();
+      Bool_t dozrc = fDestroyOnZeroRefCnt;
+      fDestroyOnZeroRefCnt = kFALSE;
+      ew_slot->PopulateSlot(fEveFrame);
+      fDestroyOnZeroRefCnt = dozrc;
+      fEveFrame = 0;
+   }
+
+   TEveElementList::Destroy();
+}
+
+//______________________________________________________________________________
+void TEveWindow::DestroyWindowAndSlot()
+{
+   printf("TEveWindow::DestroyWindowAndSlot '%s' '%s', cnt=%d\n", GetElementName(), ClassName(), fDenyDestroy);
+
+   if (fEveFrame != 0 && fDenyDestroy == 1)
+   {
+      fEveFrame->RelinquishEveWindow();
+      fEveFrame->Destroy();
+      fEveFrame = 0;
+   }
+
+   TEveElementList::Destroy();
+}
+
+//______________________________________________________________________________
+void TEveWindow::ClearEveFrame()
+{
+   // Clears eve-frame associated with this window.
+   // This is used in special case when the window is embedded in a foreign
+   // GUI container and gets deleted from this side.
+   // In particular, this happens when TRootBrowser closes a tab.
+
+   fEveFrame = 0;
+}
+
+//______________________________________________________________________________
+void TEveWindow::PopulateSlot(TEveCompositeFrame* ef)
+{
+   TEveWindow* my_ex_parent = fEveFrame ? fEveFrame->fEveParentWindow : 0;
+
+   TEveWindow* ex_win = ef->fEveWindow;
+
+   if (ef->fEveParentWindow)
+   {
+      if (ex_win) ef->fEveParentWindow->RemoveElement(ex_win);
+      ef->fEveParentWindow->AddElement(this);
+   }
+   else
+   {
+      if (ex_win) gEve->GetWindows()->RemoveElement(ex_win);
+      gEve->GetWindows()->AddElement(this);
+   }
+
+   if (my_ex_parent)
+   {
+      my_ex_parent->RemoveElement(this);
+   }
+
+   if (ex_win)
+      ex_win->fEveFrame = 0;
+   ef->ChangeEveWindow(this); // XXXX
+   fEveFrame = ef;
+
+   fEveFrame->fTitleBar->SetText(GetElementName());
+
+   fEveFrame->Layout();
+}
+
+//______________________________________________________________________________
+void TEveWindow::SetShowTitleBar(Bool_t x)
+{
+   if (fShowTitleBar == x)
+      return;
+
+   fShowTitleBar = x;
+   fEveFrame->SetShowTitleBar(fShowTitleBar);
+   fEveFrame->Layout();
+}
+
+//______________________________________________________________________________
+void TEveWindow::TitleBarClicked()
+{
+   if (fgCurrentWindow == this)
+   {
+      SetCurrent(kFALSE);
+      fgCurrentWindow = 0;
+   }
+   else
+   {
+      if (fgCurrentWindow)
+      {
+         fgCurrentWindow->SetCurrent(kFALSE);
+      }
+      fgCurrentWindow = this;
+      SetCurrent(kTRUE);
+      gEve->GetSelection()->UserPickedElement(this, kFALSE);
+   }
+}
+
+//______________________________________________________________________________
+void TEveWindow::SetCurrent(Bool_t curr)
+{
+   fEveFrame->SetCurrent(curr);
+}
+
+//------------------------------------------------------------------------------
+// Static helper functions.
+//------------------------------------------------------------------------------
+
+//______________________________________________________________________________
+TEveWindowSlot* TEveWindow::CreateDefaultWindowSlot()
+{
+   return new TEveWindowSlot("Free Window Slot", "A free window slot, can become a container or swallow a window.");
+}
+
+//______________________________________________________________________________
+TEveWindowSlot* TEveWindow::CreateWindowInTab(TGTab* tab, TEveWindow* eve_parent)
+{
+   TGCompositeFrame *parent = tab->AddTab("<unused>");
+
+   TEveCompositeFrameInTab *slot = new TEveCompositeFrameInTab(parent, eve_parent, tab);
+
+   TEveWindowSlot* ew_slot = TEveWindow::CreateDefaultWindowSlot();
+   ew_slot->PopulateSlot(slot);
+
+   parent->AddFrame(slot, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
+   slot->MapWindow();
+
+   tab->Layout();
+
+   return ew_slot;
+}
+
+
+//==============================================================================
+// TEveWindowSlot
+//==============================================================================
+
+//______________________________________________________________________________
+// Description of TEveWindowSlot
+//
+
+ClassImp(TEveWindowSlot);
+
+//______________________________________________________________________________
+TEveWindowSlot::TEveWindowSlot(const Text_t* n, const Text_t* t) :
+   TEveWindow(n, t),
+   fEmptyButt(0)
+{
+   // Constructor.
+
+   fEmptyButt = new TGTextButton(0, "    <empty>\nclick to select");
+   fEmptyButt->ChangeOptions(kRaisedFrame);
+   fEmptyButt->SetTextJustify(kTextCenterX | kTextCenterY);
+
+   fEmptyButt->Connect("Clicked()", "TEveWindow", this, "TitleBarClicked()");
+}
+
+//______________________________________________________________________________
+TEveWindowSlot::~TEveWindowSlot()
+{
+   delete fEmptyButt;
+}
+
+//______________________________________________________________________________
+TGFrame* TEveWindowSlot::GetGUIFrame()
+{
+   return fEmptyButt;
+}
+
+//______________________________________________________________________________
+void TEveWindowSlot::SetCurrent(Bool_t curr)
+{
+   TEveWindow::SetCurrent(curr);
+
+   if (curr)
+      fEmptyButt->SetBackgroundColor(fgCurrentBackgroundColor);
+   else
+      fEmptyButt->SetBackgroundColor(fEmptyButt->GetDefaultFrameBackground());
+   gClient->NeedRedraw(fEmptyButt);
+}
+
+//______________________________________________________________________________
+TEveWindowPack* TEveWindowSlot::MakePack()
+{
+   // A pack is created in place of this window-slot.
+   // This window-slot will auto-destruct.
+
+   TGPack* pack = new TGPack();
+   pack->SetVertical(kFALSE);
+
+   TEveWindowPack* eve_pack = new TEveWindowPack
+      (pack, "Pack", "Window container for horizontal and vertical stacking.");
+
+   eve_pack->PopulateSlot(fEveFrame);
+
+   return eve_pack;
+}
+
+//______________________________________________________________________________
+TEveWindowTab* TEveWindowSlot::MakeTab()
+{
+   // A tab is created in place of this window-slot.
+   // This window-slot will auto-destruct.
+
+   TGTab* tab = new TGTab();
+
+   TEveWindowTab* eve_tab= new TEveWindowTab
+      (tab, "Tab", "Window container for horizontal and vertical stacking.");
+
+   eve_tab->PopulateSlot(fEveFrame);
+
+   return eve_tab;
+}
+
+
+//==============================================================================
+// TEveWindowMainFrame
+//==============================================================================
+
+//______________________________________________________________________________
+// Description of TEveWindowMainFrame
+//
+
+ClassImp(TEveWindowMainFrame);
+
+//______________________________________________________________________________
+TEveWindowMainFrame::TEveWindowMainFrame(const Text_t* n, const Text_t* t) :
+   TEveWindow (n, t),
+   fMainFrame (0)
+{
+   // Constructor.
+}
+
+//______________________________________________________________________________
+TGFrame* TEveWindowMainFrame::GetGUIFrame()
+{
+   return fMainFrame;
+}
+
+
+//==============================================================================
+// TEveWindowPack
+//==============================================================================
+
+//______________________________________________________________________________
+// Description of TEveWindowPack
+//
+
+ClassImp(TEveWindowPack);
+
+//______________________________________________________________________________
+TEveWindowPack::TEveWindowPack(TGPack* p, const Text_t* n, const Text_t* t) :
+   TEveWindow   (n, t),
+   fPack        (p)
+{
+   // Constructor.
+}
+
+//______________________________________________________________________________
+TEveWindowPack::~TEveWindowPack()
+{
+   // Destructor.
+
+   delete fPack;
+}
+
+//______________________________________________________________________________
+TGFrame* TEveWindowPack::GetGUIFrame()
+{
+   return fPack;
+}
+
+//______________________________________________________________________________
+TEveWindowSlot* TEveWindowPack::NewSlot()
+{
+   TEveCompositeFrame* slot = new TEveCompositeFrameInPack(fPack, this, fPack);
+
+   TEveWindowSlot* ew_slot = TEveWindow::CreateDefaultWindowSlot();
+   ew_slot->PopulateSlot(slot);
+
+   fPack->AddFrame(slot);
+   slot->MapWindow();
+
+   fPack->Layout();
+
+   return ew_slot;
+}
+
+//______________________________________________________________________________
+void TEveWindowPack::FlipOrientation()
+{
+   fPack->SetVertical( ! fPack->GetVertical());
+}
+
+
+//==============================================================================
+// TEveWindowTab
+//==============================================================================
+
+//______________________________________________________________________________
+// Description of TEveWindowTab
+//
+
+ClassImp(TEveWindowTab);
+
+//______________________________________________________________________________
+TEveWindowTab::TEveWindowTab(TGTab* tab, const Text_t* n, const Text_t* t) :
+   TEveWindow(n, t),
+   fTab (tab)
+{
+   // Constructor.
+}
+
+//______________________________________________________________________________
+TGFrame* TEveWindowTab::GetGUIFrame()
+{
+   return fTab;
+}
+
+//______________________________________________________________________________
+TEveWindowSlot* TEveWindowTab::NewSlot()
+{
+   return TEveWindow::CreateWindowInTab(fTab, this);
+}
diff --git a/graf3d/eve/src/TEveWindowEditor.cxx b/graf3d/eve/src/TEveWindowEditor.cxx
new file mode 100644
index 00000000000..3c61e79e198
--- /dev/null
+++ b/graf3d/eve/src/TEveWindowEditor.cxx
@@ -0,0 +1,68 @@
+// @(#)root/eve:$Id$
+// Author: Matevz Tadel 2007
+
+/*************************************************************************
+ * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
+ * All rights reserved.                                                  *
+ *                                                                       *
+ * For the licensing terms see $ROOTSYS/LICENSE.                         *
+ * For the list of contributors see $ROOTSYS/README/CREDITS.             *
+ *************************************************************************/
+
+#include "TEveWindowEditor.h"
+#include "TEveWindow.h"
+
+#include "TVirtualPad.h"
+#include "TColor.h"
+
+// Cleanup these includes:
+#include "TGLabel.h"
+#include "TGButton.h"
+#include "TGNumberEntry.h"
+#include "TGColorSelect.h"
+#include "TGDoubleSlider.h"
+
+
+//______________________________________________________________________________
+// GUI editor for TEveWindow.
+//
+
+ClassImp(TEveWindowEditor);
+
+//______________________________________________________________________________
+TEveWindowEditor::TEveWindowEditor(const TGWindow *p, Int_t width, Int_t height,
+             UInt_t options, Pixel_t back) :
+   TGedFrame(p, width, height, options | kVerticalFrame, back),
+   fM(0),
+   fShowTitleBar(0)
+{
+   // Constructor.
+
+   MakeTitle("TEveWindow");
+
+   fShowTitleBar = new TGCheckButton(this, "Show title-bar");
+   AddFrame(fShowTitleBar); // new TGLayoutHints());
+   fShowTitleBar->Connect("Clicked()", "TEveWindowEditor", this,
+                          "DoShowTitleBar()");
+}
+
+/******************************************************************************/
+
+//______________________________________________________________________________
+void TEveWindowEditor::SetModel(TObject* obj)
+{
+   // Set model object.
+
+   fM = dynamic_cast<TEveWindow*>(obj);
+
+   fShowTitleBar->SetState(fM->GetShowTitleBar() ? kButtonDown : kButtonUp);
+}
+
+//______________________________________________________________________________
+void TEveWindowEditor::DoShowTitleBar()
+{
+   // Slot for ShowTitleBar.
+
+   fM->SetShowTitleBar(fShowTitleBar->IsOn());
+   Update();
+}
diff --git a/graf3d/gl/inc/TGLSAViewer.h b/graf3d/gl/inc/TGLSAViewer.h
index a6a0f9be75b..5d1b572b961 100644
--- a/graf3d/gl/inc/TGLSAViewer.h
+++ b/graf3d/gl/inc/TGLSAViewer.h
@@ -73,7 +73,8 @@ private:
    TString            fDirName;
    Int_t              fTypeIdx;
    Bool_t             fOverwrite;
-   TGMenuBar          *fMenuBar;
+   TGMenuBar         *fMenuBar;
+   Bool_t             fDeleteMenuBar;
 
    // Initial window positioning
    static const Int_t fgInitX;
@@ -81,8 +82,8 @@ private:
    static const Int_t fgInitW;
    static const Int_t fgInitH;
 
-   static const char * fgHelpText1;
-   static const char * fgHelpText2;
+   static const char *fgHelpText1;
+   static const char *fgHelpText2;
 
    void CreateMenus();
    void CreateFrames();
@@ -105,6 +106,7 @@ public:
 
    void   Show();
    void   Close();
+   void   DeleteMenuBar();
 
    // GUI events - editors, frame etc
    Bool_t ProcessFrameMessage(Long_t msg, Long_t parm1, Long_t);
diff --git a/graf3d/gl/src/TGLSAViewer.cxx b/graf3d/gl/src/TGLSAViewer.cxx
index d6b907fc2c1..96e3c7e531e 100644
--- a/graf3d/gl/src/TGLSAViewer.cxx
+++ b/graf3d/gl/src/TGLSAViewer.cxx
@@ -168,7 +168,8 @@ TGLSAViewer::TGLSAViewer(TVirtualPad *pad) :
    fDirName("."),
    fTypeIdx(0),
    fOverwrite(kFALSE),
-   fMenuBar(0)
+   fMenuBar(0),
+   fDeleteMenuBar(kFALSE)
 {
    // Construct a standalone viewer, bound to supplied 'pad'.
    fFrame = new TGLSAFrame(*this);
@@ -208,7 +209,8 @@ TGLSAViewer::TGLSAViewer(const TGWindow *parent, TVirtualPad *pad, TGedEditor *g
    fGedEditor(ged),
    fPShapeWrap(0),
    fTypeIdx(0),
-   fMenuBar(0)
+   fMenuBar(0),
+   fDeleteMenuBar(kFALSE)
 {
    // Construct an embedded standalone viewer, bound to supplied 'pad'.
    //
@@ -250,6 +252,9 @@ TGLSAViewer::~TGLSAViewer()
    delete fCameraMenu;
    delete fFileSaveMenu;
    delete fFileMenu;
+   if(fDeleteMenuBar) {
+      delete fMenuBar;
+   }
    delete fFrame;
    fGLWidget = 0;
 }
@@ -379,6 +384,13 @@ void TGLSAViewer::Close()
    delete this;
 }
 
+//______________________________________________________________________________
+void TGLSAViewer::DeleteMenuBar()
+{
+   // Delete the menu bar.
+   fDeleteMenuBar=kTRUE;
+}
+
 //______________________________________________________________________________
 Bool_t TGLSAViewer::ProcessFrameMessage(Long_t msg, Long_t parm1, Long_t)
 {
diff --git a/tutorials/eve/cms_calo.C b/tutorials/eve/cms_calo.C
index 71a1f0702ab..1b262c60f19 100644
--- a/tutorials/eve/cms_calo.C
+++ b/tutorials/eve/cms_calo.C
@@ -136,8 +136,7 @@ TEveCaloDataVec* MakeVecData(TH2* h1, TH2* h2)
     }
   }
 
-  data->SetEtaBins(new TAxis(100, ax->GetBinLowEdge(1), ax->GetBinUpEdge(ax->GetLast())));
-  data->SetPhiBins(new TAxis(100, ay->GetBinLowEdge(1), ay->GetBinUpEdge(ay->GetLast())));
+  data->SetAxisFromBins();
   data->DataChanged();
 
   return data;
diff --git a/tutorials/eve/cms_calo_detail.C b/tutorials/eve/cms_calo_detail.C
index 2064f4a7af2..7798e0fa4bf 100644
--- a/tutorials/eve/cms_calo_detail.C
+++ b/tutorials/eve/cms_calo_detail.C
@@ -112,19 +112,16 @@ void cms_calo_detail()
   data->FillSlice(0, 6);
   data->FillSlice(1, 0);
 
-  data->SetEtaBins(new TAxis(10, 0.08, 0.16));
-  data->SetPhiBins(new TAxis(10, 0.40, 0.50));
-
+  data->SetAxisFromBins();
   data->DataChanged();
 
   // lego
 
   TEveCaloLego* lego = new TEveCaloLego(data);
+  lego->SetAutoRebin(kFALSE);
   lego->SetPlaneColor(kBlue-5);
   lego->Set2DMode(TEveCaloLego::kValSize);
-  lego->SetName("TwoHistLego");
-  lego->SetEta(0.08, 0.16); // eta min, max
-  lego->SetPhiWithRng(0.45, 0.05); // phi, half-range
+  lego->SetName("Calo Detail");
   gEve->AddElement(lego);
 
   // overlay lego
diff --git a/tutorials/eve/test_windows.C b/tutorials/eve/test_windows.C
new file mode 100644
index 00000000000..7f6ee99effc
--- /dev/null
+++ b/tutorials/eve/test_windows.C
@@ -0,0 +1,36 @@
+void test_windows()
+{
+   TEveManager::Create();
+
+   TEveWindowSlot *slot = 0;
+
+   // ----------------------------------------------------------------
+
+   slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
+
+   TEveWindowPack* pack1 = slot->MakePack();
+   pack1->NewSlot();
+   slot = pack1->NewSlot();
+   
+   TEveWindowPack* pack2 = slot->MakePack();
+   pack2->FlipOrientation();
+
+   pack2->NewSlot();
+   pack2->NewSlot();
+
+   // ----------------------------------------------------------------
+
+   slot = TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
+
+   TEveWindowTab* tab1 = slot->MakeTab();
+   tab1->NewSlot();
+   slot = tab1->NewSlot();
+
+   TEveWindowTab* tab2 = slot->MakeTab();
+   tab2->NewSlot();
+   tab2->NewSlot();
+
+   // ----------------------------------------------------------------
+
+   gEve->GetBrowser()->GetTabRight()->SetTab(1);
+}
-- 
GitLab