TGMdiFrame

Hi,

I am using TGMdiFrame class and in my Gui program I would like to know whether a TGMdiFrame “window” is closed or not, and if it is then I would like to reuse it with all of its child objects…

The problem is that in my Gui program I want to let the users to close a window (in the window I have e.g. an embedded canvas, in which I plot a TCanvas, on which I draw a histogram). If the user closes one of such a TGMdiFrame “window” (by pressing e.g. the little “x” in top right hand corner of the window) then I would like to handle this case in such a way that the parent TGMdiFrame and all of its child objects should be reused again and they “stay together”, so that if one wanted to show the window again (the original TGMdiFrame with all of its child objects) then one could also redraw (or MapSubwindows(), etc) the whole thing again.

Another aspect of this is that how can one check with a boolean returning function whether a TGMdiFrame is closed or not (i.e. whether the “x” was pressed by the user or not)?

Is this trivial? If yes, please, can someone show a minimal example?

Thanx,
Balint

Hi,
I think there is already an example showing exactly what you ask for, just take a look at $ROOTSYS/test/gui/mditest.C:

fMdiFrame->Connect("CloseWindow()", "TGMdiTestSubclass", this, "CloseWindow()"); fMdiFrame->DontCallClose(); HTH,
Bertrand.

Hi,

somehow it still doesn’t solve my problem. What I want is to redraw a histrogram (data is read for each redraw from different resources) in the same TCanvas of the same TRootEmbeddedCanvas of the same TGMdiFrame. So I want to construct all this structure in the begining and when the user presses a button (e.g. “Draw”) after loading the necessary data into memory, then I want to draw the histogram into the same canvas.

If I make this structure in the construction of my gui class then how can I access the same TCanvas from a member function?

Let me write you how I do it (just the core).
So let’s say I declare the member variables and functions in the class declaration:

class TGAppMainFrame  {
...
public:

  TGMainFrame     *fMain;
  TGMdiMainFrame  *fMainFrame;
  TGMdiMenuBar    *fMenuBar;
  TGMdiFrame * plot_alldata;

  TRootEmbeddedCanvas * fRootEmbeddedCanvas_alldata;
  Int_t wfRootEmbeddedCanvas;   

  TCanvas * c_alldata;
  TH1F * alldata;

public:
   void DrawAlldata();
...
};

then in the constructor of TGAppMainFrame I make the all frames and I map the subwindows, etc., but the important part would be:

TGAppMainFrame::TGAppMainFrame(const TGWindow *p, int w, int h){
...

   plot_alldata = new TGMdiFrame(fMainFrame, 500, 300);
   plot_alldata->DontCallClose();
   plot_alldata->SetWindowName("All data");
   fRootEmbeddedCanvas_alldata = new TRootEmbeddedCanvas(0,plot_alldata,500,300,kSunkenFrame, ucolor);

   wfRootEmbeddedCanvas = fRootEmbeddedCanvas_alldata->GetCanvasWindowId();

    c_alldata = new TCanvas("c_alldata", 10, 10, wfRootEmbeddedCanvas);
    fRootEmbeddedCanvas_alldata->AdoptCanvas(c_alldata);
    plot_alldata->AddFrame(fRootEmbeddedCanvas_alldata, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2));
    plot_alldata->SetMdiHints(kMdiDefaultHints | kMdiHelp);
    plot_alldata->MapSubwindows();
    plot_alldata->Layout(); 
...
}

Then I connect a button to the function DrawAlldata() in which I want to draw the histogram, but if I do that by just simply

 void TGAppMainFrame::DrawAlldata(){  
...
    c_alldata->cd();
    alldata->Draw("cols");
...
}

it doesn’t work like this. How should I do this?

Thanx,
Balint

Nevermind, I stupidly set to some pointers of the frames to NULL after drawing them…no it works

Balint

Hi Balint,

Good news :slight_smile:
But as I was ready with a simple example, I post it here anyway, and it is maybe a bit simpler… (just take a look at TRootEmbeddedCanvas - TCanvas creation) :wink:

Cheers,
Bertrand.
mdisimple.C (7.46 KB)

Hi,

thanx for the example! :slight_smile:
It is really more simpler in the way you show it in your example.

Thank you again!

Balint