Re: deleting TGFrame

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Wed Mar 22 2000 - 15:56:31 MET


Hi Judith,

   you have to explicitely destroy the vfr1 window before deleting it.
If not the associated X-window lives on and is drawn as a grey blob.
It probably should be called from the destructor, but for the time being
it needs to be done by hand (it is called however in the MainFrame and
TransientFrame dtors). So your example should look like:

  // if I don't add the frame using this 2 lines I'll get a blank area:
  if(i!=1) vfr->AddFrame(vfr1,lht); 
  else {
     vfr1->DestroyWindow();
     delete vfr1;
  }

or

  vfr->AddFrame(vfr1,lht); 
  if (i == 1) {
     vfr->RemoveFrame(vfr1);
     vfr1->DestroyWindow();
     delete vfr1;
  }

Cheers, Fons.



Judith Katzy wrote:
> 
> hi,
> 
> I wrote a navigator that creates subframes and buttons and attaches logic
> to them, so that it knows which frames to show after a button has been
> pushed. In that environment, I would like to create a TGFrame, that is
> child to a TGCompositeFrame and delete it later, in case I find that
> an identical TGFrame already exist. For some reasons I get a blank
> rectangular region in the TGCompositeFrame if I delete/don't add the frame
> to it. See an example macro below.
> 
> How can I get back to the state before I created the childframe?
> (I tried any variation of TGCompositeFrame::RemoveFrame(..) & co., but
> nothing worked)
> 
> thanks for any help,
> Judith
> 
> {
> TGLayoutHints *lht =  new TGLayoutHints( kLHintsTop, 2, 2, 2, 2);
> TGLayoutHints *lhl =  new TGLayoutHints( kLHintsLeft, 2, 2, 2, 2);
> 
> TGMainFrame *mf = new TGMainFrame(gClient->GetRoot(),200,200);
> TGVerticalFrame *vfr = new TGVerticalFrame(mf, 100,100);
> mf->AddFrame(vfr);
> 
> TGHorizontalFrame *hfr = new TGHorizontalFrame(vfr, 100,100);
> TGTextButton *b1 = new TGTextButton(hfr,"horizontal1");
> hfr->AddFrame(b1,lhl);
> TGTextButton *b2 = new TGTextButton(hfr,"horizontal2");
> hfr->AddFrame(b2,lhl);
> vfr->AddFrame(hfr, lht);
> Char_t name[25];
> 
> for(int i=0; i<=3; i++)
> {
>   sprintf(name,"test%d",i);
>   TGVerticalFrame *vfr1 = new TGVerticalFrame(vfr, 100,100);
>   TGTextButton *b = new TGTextButton(vfr1,name);
>   vfr1->AddFrame(b,lhl);
>   // if I use this line instead of the following 2 lines I see the full
>   // picture:
>   //vfr->AddFrame(vfr1,lht);
> 
>   // if I don't add the frame using this 2 lines I'll get a blank area:
>   if(i!=1)  vfr->AddFrame(vfr1,lht);
>   else delete vfr1;
> }
> mf->Resize(200,200);
> mf->MapSubwindows();
> mf->ShowFrame(vfr);
> mf->MapRaised();
> }

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7677910



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:21 MET