// Mainframe macro generated from application: /usr/local/fndprg/root/bin/root.exe
// By ROOT version 5.06/00 on 2005-11-07 11:00:43

#if !defined( __CINT__) || defined (__MAKECINT__)

#ifndef ROOT_TGMenu
#include "TGMenu.h"
#endif
#ifndef ROOT_TGButtonGroup
#include "TGButtonGroup.h"
#endif
#ifndef ROOT_TGCanvas
#include "TGCanvas.h"
#endif
#ifndef ROOT_TRootCanvas
#include "TRootCanvas.h"
#endif
#ifndef ROOT_TRootGuiBuilder
#include "TRootGuiBuilder.h"
#endif
#ifndef ROOT_TGDockableFrame
#include "TGDockableFrame.h"
#endif
#ifndef ROOT_TGToolBar
#include "TGToolBar.h"
#endif
#ifndef ROOT_TGButton
#include "TGButton.h"
#endif
#ifndef ROOT_TGToolTip
#include "TGToolTip.h"
#endif
#ifndef ROOT_TGuiBldDragManager
#include "TGuiBldDragManager.h"
#endif
#ifndef ROOT_TGMdiMainFrame
#include "TGMdiMainFrame.h"
#endif
#ifndef ROOT_TGLabel
#include "TGLabel.h"
#endif
#ifndef ROOT_TG3DLine
#include "TG3DLine.h"
#endif
#ifndef ROOT_TGNumberEntry
#include "TGNumberEntry.h"
#endif
#ifndef ROOT_TGuiBldHintsButton
#include "TGuiBldHintsButton.h"
#endif
#ifndef ROOT_TGuiBldHintsEditor
#include "TGuiBldHintsEditor.h"
#endif
#ifndef ROOT_TGuiBldEditor
#include "TGuiBldEditor.h"
#endif
#ifndef ROOT_TGShutter
#include "TGShutter.h"
#endif
#ifndef ROOT_TGStatusBar
#include "TGStatusBar.h"
#endif
#ifndef ROOT_TGTab
#include "TGTab.h"
#endif
#ifndef ROOT_TGSplitter
#include "TGSplitter.h"
#endif
#ifndef ROOT_TGMdiMenu
#include "TGMdiMenu.h"
#endif
#ifndef ROOT_TGMdiDecorFrame
#include "TGMdiDecorFrame.h"
#endif
#ifndef ROOT_TGMdiFrame
#include "TGMdiFrame.h"
#endif
#ifndef ROOT_TGuiBldQuickHandler
#include "TGuiBldQuickHandler.h"
#endif
#ifndef ROOT_TGListBox
#include "TGListBox.h"
#endif
#ifndef ROOT_TGListView
#include "TGListView.h"
#endif
#ifndef ROOT_TGFSContainer
#include "TGFSContainer.h"
#endif
#ifndef ROOT_TGFSComboBox
#include "TGFSComboBox.h"
#endif
#ifndef ROOT_TGFileDialog
#include "TGFileDialog.h"
#endif
#ifndef ROOT_TGScrollBar
#include "TGScrollBar.h"
#endif

#endif

#include <Riostream.h>
#include <TDirectory.h>
#include <TCanvas.h>
#include <TCanvasImp.h>

class MyControl {
  
private:
  TGMainFrame *fMainFrame;
  TGVerticalFrame *frame427;
  
  TGTextButton *frame428;
  TGTextButton *frame429;
  TGTextButton *frame442;
  
  TGGroupFrame *frame449;
  TGTextButton *fButClose;
  
public:
  MyControl();
  virtual ~MyControl();

  void BuildGUI();
  void MapGUI();
  void CloseGUI();
  void MakeConnections();

  void Pop1();
  void Pop2();

  void PopPad();


  ClassDef(MyControl,0)
};


ClassImp(MyControl)

//___________________
MyControl::MyControl(){

}

//___________________
MyControl::~MyControl(){

}

//___________________________
void MyControl::BuildGUI(){
  // main frame
  fMainFrame = new TGMainFrame(gClient->GetRoot(),10,10,kMainFrame | kVerticalFrame);
  fMainFrame->SetLayoutBroken(kTRUE);

  // vertical frame
  frame427 = new TGVerticalFrame(fMainFrame,210,180,kVerticalFrame);
  frame427->SetLayoutBroken(kTRUE);
   
  frame428 = new TGTextButton(frame427,"Canvas 1");
  frame428->Resize(170,40);
  frame427->AddFrame(frame428, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
  frame428->MoveResize(20,20,170,40);

  frame429 = new TGTextButton(frame427,"Canvas 2");
  frame429->Resize(170,40);
  frame427->AddFrame(frame429, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
  frame429->MoveResize(20,70,170,40);
   
  frame442 = new TGTextButton(frame427,"Canvas 3");
  frame442->Resize(170,40);
  frame427->AddFrame(frame442, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
  frame442->MoveResize(20,120,170,40);

  fMainFrame->AddFrame(frame427, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
  frame427->MoveResize(0,0,210,180);

  // "frame449" group frame
  frame449 = new TGGroupFrame(fMainFrame,"frame449");
  frame449->SetLayoutBroken(kTRUE);

  fButClose = new TGTextButton(frame449,"Close");
  fButClose->Resize(200,40);
  frame449->AddFrame(fButClose, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
  fButClose->MoveResize(20,30,200,40);

  frame449->SetLayoutManager( new TGVerticalLayout(frame449));
  frame449->Resize(230,180);
  fMainFrame->AddFrame(frame449, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
  frame449->MoveResize(210,0,230,180);
}

//______________________
void MyControl::MapGUI(){
  fMainFrame->MapSubwindows();

  fMainFrame->Resize(fMainFrame->GetDefaultSize());
  fMainFrame->MapWindow();
  fMainFrame->Resize(444,182);
}

//______________________
void MyControl::CloseGUI(){
  
  if(fMainFrame->IsMapped()){
    cout << "main frame mapped: closing" << endl;
    fMainFrame->SendCloseMessage();
  }
  else cout << "main frame not mapped: cleaning up" << endl;
  fMainFrame->Cleanup();
  
}

//______________________
void MyControl::MakeConnections(){
  
  fButClose ->Connect("Clicked()", "MyControl", this, "CloseGUI()");
  frame428->Connect("Clicked()", "MyControl", this, "Pop1()");
  frame429->Connect("Clicked()", "MyControl", this, "Pop2()");
}

//______________________
void MyControl::Pop1(){
  ((TCanvas *)gDirectory->FindObject("ca1"))->cd();
  PopPad();
}
//______________________
void MyControl::Pop2(){
  ((TCanvas *)gDirectory->FindObject("ca2"))->cd();
  //((TCanvas *)gDirectory->FindObject("ca2"))->GetCanvasImp()->RaiseWindow();
  PopPad();
}


//______________________
void MyControl::PopPad(){
  gPad->Modified();
  gPad->Update();
  cout << gPad->GetName() << endl;
  //  gPad->Pop();
  gPad->GetCanvas()->GetCanvasImp()->RaiseWindow();
}

//______________________
void ControlCanvas_Class(){

  TCanvas *canv1 = new TCanvas("ca1","c1",300,30,400,400);
  TCanvas *canv2 = new TCanvas("ca2","c2",300,30,400,400);

  MyControl *cont = new MyControl();
  cont->BuildGUI();
  cont->MapGUI();
  cont->MakeConnections();
}

