Re: [ROOT] Problem to scroll TRootEmbeddedCanvas

From: cstrato (aon.912121399@aon.at)
Date: Sat May 03 2003 - 18:40:40 MEST


Dear Fons

Thank you for adding these methods.
Sorrowly, I do not get the expected behavior:
1, Although canvas is now constant, the size is 100x100 instead of 600x600
2, There are no scrollbars to scroll, if the window is smaller than the 
canvas.

Enlosed, I am sending you a macro, which displays in the 1.tab the
unwanted behavior, and in the 2.tab the wanted behavior.
It is not clear to me why TRootEmbeddedCanvas does not show scrollbars,
even though it is derived from TGCanvas?

Best regards
Christian

Fons Rademakers wrote:

>Hi Christian,
>
> I've added the methods: SetAutoFit() and GetAutoFit(). Try using it
>like:
>TRootEmbeddedCanvas *embedded = new TRootEmbeddedCanvas(0, p, 100, 100);
>[note name must be 0, not null string ""]
>Int_t wid = embedded->GetCanvasWindowId();
>TCanvas *myc = new TCanvas("myname", 600, 600, wid);
>embedded->SetAutoFit(kFALSE);
>embedded->AdoptCanvas(myc);
>
>Let me know if this works for you.
>
>Cheers, Fons.
>
>On Sun, 2003-04-27 at 19:06, cstrato wrote:
>  
>
>>Dear Rooters
>>
>>In my GUI-application I want to create a canvas of fixed size in a
>>TGCanvas with scrollbars.
>>
>>Sorrowly, I am unable to use TRootEmbeddedCanvas for this purpose,
>>since for some reason it is not possible to set:  fAutoFit = kFALSE;
>>
>>For some reason it is also not possible to embed  TRootEmbeddedCanvas
>>in TGCanvas, I get no scrollbars.
>>Only embedding TRootEmbeddedCanvas in TGCompositeFrame,
>>which is embedded in TGCanvas did help (pretty complicated).
>>
>>Since I want to set a checkbox, determining, if the canvas should
>>have fixed size or keep the size of its container, it would be great,
>>if a function SetAutoFit(kFALSE) could be added.
>>
>>Thank you in advance.
>>
>>Best regards
>>Christian
>>_._._._._._._._._._._._._._._._
>>C.h.i.s.t.i.a.n S.t.r.a.t.o.w.a
>>V.i.e.n.n.a       A.u.s.t.r.i.a
>>_._._._._._._._._._._._._._._._
>>    
>>



// Test gui

class MyFrame {

   RQ_OBJECT("MyFrame")

   private:
      TGMainFrame        *fMain;

   // MenuBar Frame
      TGPopupMenu        *fMenuFile;
      TGMenuBar          *fMenuBar;
      TGHorizontal3DLine *fLineH1;

      TGHorizontalFrame  *fHF1;
      TGVerticalFrame     *fVF1;
      TGCompositeFrame     *fFPlot;
      TGTab                 *fTabCvs;

   // Test Frame
      TRootEmbeddedCanvas    *fRECvs1;
      TCanvas                 *fCanvas1;
      TGCanvas                *fGCanvas2;
      TGCompositeFrame         *fFRE2;
      TRootEmbeddedCanvas       *fRECvs2;

//Test:
      TRootEmbeddedCanvas  *fCvs;

   // Layout hints
      TGLayoutHints      *fMenuBarLayout;
      TGLayoutHints      *fMenuBarItemLayout;
      TGLayoutHints      *fMenuBarHelpLayout;
      TGLayoutHints      *fLineLayout;
      TGLayoutHints      *fLayout;

      TGLayoutHints      *fHintTL;
      TGLayoutHints      *fHintTXY;
      TGLayoutHints      *fHintRXY;
      TGLayoutHints      *fHintLY;
      TGLayoutHints      *fHintXY;

      TList    *fTrash;

      Int_t     fPlotID;

   public:
      MyFrame(const TGWindow *window, UInt_t w, UInt_t h);
      virtual ~MyFrame();

   // Slots
      void DoCloseWindow();

   private:
      void CreateMenuBar();
      void DeleteMenuBar();
      void CreateFrame1(TGTab *tab);
      void DeleteFrame1();
      void CreateFrame2(TGTab *tab);
      void DeleteFrame2();

//      ClassDef(MyFrame,0) //MainFrame
};

//______________________________________________________________________________
//______________________________________________________________________________

//debug: print function names
const Bool_t kCS  = 1; 

//ClassImp(MyFrame);

// Menu commands
enum EMenuCommands {
   M_FILE,
   M_FILE_EXIT,
};

//______________________________________________________________________________
MyFrame::MyFrame(const TGWindow *window, UInt_t w, UInt_t h)
{
   if(kCS) cout << "------MyFrame::MyFrame------" << endl;

   fTrash   = new TList();
   fHintTL  = new TGLayoutHints(kLHintsTop | kLHintsLeft);
   fHintTXY = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY);
   fHintRXY = new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY);
   fHintLY  = new TGLayoutHints(kLHintsLeft | kLHintsExpandY);
   fHintXY  = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);

   fMain = new TGMainFrame(window, w, h);
   fMain->Connect("CloseWindow()", "MyFrame", this, "DoCloseWindow()");

// Create menus
   CreateMenuBar();

// Basic frame layout
   fLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY);
   fHF1 = new TGHorizontalFrame(fMain, 20, 20);
   fMain->AddFrame(fHF1, fLayout);

   fVF1 = new TGVerticalFrame(fHF1, 300, 200);
   fHF1->AddFrame(fVF1, fLayout);

// Plot Frame
   fFPlot = new TGCompositeFrame(fVF1,0,0, kVerticalFrame);
   fVF1->AddFrame(fFPlot, fHintTXY);

// Frame for Tab widgets
   fTabCvs = new TGTab(fFPlot, 20, 20);
   fFPlot->AddFrame(fTabCvs, fHintTXY);

// Create Test Frame
   CreateFrame1(fTabCvs);
   CreateFrame2(fTabCvs);

   TGLayoutHints *hint = 0;
   hint = new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX);
   fTrash->Add(hint);
   fCvs = new TRootEmbeddedCanvas("canvasA",fVF1,300,40);
   fVF1->AddFrame(fCvs, hint);
//   fVF1->AddFrame(fCvs, fLayout);

// Main settings
   fMain->SetWindowName("MyGui");
   fMain->MapSubwindows();
   fMain->Resize(fMain->GetDefaultSize());
   fMain->MapWindow();
   fMain->Move(20, 20);
}//Constructor

//______________________________________________________________________________
MyFrame::~MyFrame()
{
   if(kCS) cout << "------MyFrame::~MyFrame------" << endl;

   DeleteFrame2();
   DeleteFrame1();
   DeleteMenuBar();

   delete fTabCvs; delete fFPlot;
   delete fCvs; 
   delete fVF1; 
   delete fHF1; 
   delete fMain;

   delete fLayout;
   delete fHintTL; delete fHintTXY; delete fHintRXY; delete fHintLY; delete fHintXY;

   fTrash->Delete();
   delete fTrash;
}//Destructor

//______________________________________________________________________________
void MyFrame::CreateMenuBar()
{
   if(kCS) cout << "------MyFrame::CreateMenuBar------" << endl;

// File menu
   fMenuFile = new TGPopupMenu(gClient->GetRoot());
   fMenuFile->AddEntry("&Exit",  M_FILE_EXIT);

// Create menubar layout hints
   fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0, 0, 1, 1);
   fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
   fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);

// Add menus to MenuBar
   fMenuBar = new TGMenuBar(fMain, 1, 1, kHorizontalFrame);
   fMenuBar->AddPopup("&File",        fMenuFile, fMenuBarItemLayout);

   fMain->AddFrame(fMenuBar, fMenuBarLayout);

// Line to separate menubar
   fLineH1 = new TGHorizontal3DLine(fMain);
   fLineLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX);
   fMain->AddFrame(fLineH1, fLineLayout);
   fLineH1->DrawBorder();
}//CreateMenuBar

//______________________________________________________________________________
void MyFrame::DeleteMenuBar()
{
   if(kCS) cout << "------MyFrame::DeleteMenuBar------" << endl;

   delete fLineH1; 
   delete fMenuBar;
   delete fMenuFile; 

   delete fMenuBarLayout;
   delete fMenuBarItemLayout;
   delete fMenuBarHelpLayout;
   delete fLineLayout;
}//DeleteMenuBar

//______________________________________________________________________________
void MyFrame::DoCloseWindow()
{
   if(kCS) cout << "------MyFrame::DoCloseWindow------" << endl;

   delete this;  //does not exit root
//   gApplication->Terminate(0);  //exit root, needed for standalone App
}//DoCloseWindow

//______________________________________________________________________________
void MyFrame::CreateFrame1(TGTab *tab)
{
   if(kCS) cout << "------MyFrame::CreateFrame1------" << endl;

   TGLayoutHints *hint = 0;

   // New Tab 
   TGCompositeFrame *tabframe = 0;
   tabframe = tab->AddTab("New Canvas1");
   fRECvs1 = new TRootEmbeddedCanvas(0,tabframe,300,300);
   hint = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5);
   tabframe->AddFrame(fRECvs1, hint);
   fTrash->Add(hint);

   Int_t wid = fRECvs1->GetCanvasWindowId();
   fCanvas1 = new TCanvas("Canvas_1", 500, 500, wid);
//   fRECvs1->SetAutoFit(kTRUE);
   fRECvs1->SetAutoFit(kFALSE);
   fRECvs1->AdoptCanvas(fCanvas1);

//TEST Graphics
   Double_t x[100], y[100];
   Int_t n = 20;
   for (Int_t i=0;i<n;i++) {
     x[i] = i*0.1;
     y[i] = 10*sin(x[i]+0.2);
   }
   TGraph *gr = new TGraph(n,x,y);
   gr->Draw("AC*");
//END
}//CreateFrame

//______________________________________________________________________________
void MyFrame::DeleteFrame1()
{
   if(kCS) cout << "------MyFrame::DeleteFrame1------" << endl;

   delete fRECvs1;  //fCanvas deleted by fRECvs!
}//DeleteFrame

//______________________________________________________________________________
void MyFrame::CreateFrame2(TGTab *tab)
{
   if(kCS) cout << "------MyFrame::CreateFrame2------" << endl;

   TGLayoutHints *hint = 0;

   // New Tab 
   TGCompositeFrame *tabframe = 0;
   tabframe = fTabCvs->AddTab("New Canvas2");
   fGCanvas2 = new TGCanvas(tabframe, 300, 300, 0);
   fFRE2 = new TGCompositeFrame(fGCanvas2->GetViewPort(),500,400, kVerticalFrame);
   fGCanvas2->SetContainer(fFRE2);
   fRECvs2 = new TRootEmbeddedCanvas("canvasB",fFRE2,500,400);
   fFRE2->AddFrame(fRECvs2, fHintTL);
   hint = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5);
   tabframe->AddFrame(fGCanvas2, hint);
   fTrash->Add(hint);

//TEST Graphics
   Double_t x[100], y[100];
   Int_t n = 20;
   for (Int_t i=0;i<n;i++) {
     x[i] = i*0.1;
     y[i] = 10*sin(x[i]+0.2);
   }
   TGraph *gr = new TGraph(n,x,y);
   gr->Draw("AC*");
//END
}//CreateFrame

//______________________________________________________________________________
void MyFrame::DeleteFrame2()
{
   if(kCS) cout << "------MyFrame::DeleteFrame2------" << endl;

   delete fRECvs2; delete fFRE2; delete fGCanvas2;
}//DeleteFrame



//______________________________________________________________________________
void embedded()
{
   new MyFrame(gClient->GetRoot(), 400, 220);
}



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:11 MET