[haiku-development] Re: Hello, and a BBitmap question.

  • From: James Kim <jkim202@xxxxxxxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sat, 07 Jun 2008 18:34:28 +1200

Thanks, but something else is causing trouble now. I wanted to delete
all child views in the parent view and I have just noticed something.

Methods such as BView::RemoveSelf(), BView::RemoveChild() does not seem
to work on the parent view.

For example, I tried counting the number of parent's children after
removing each child from the parent view.

printf("%d", fParent->CountChildren());
for (int32 i = 0; i < fParent->CountChildren(); i++) {
        RemoveChild(fParent->ChildAt(i)
        printf("%d", fParent->CountChildren());
}

The result from the above code always gives 14. Strangely, I am able to
add a child to the parent view but not remove. Any help please?

I am not sure if this will make any difference to the solution, but the
parent I am currently using is BLayout::View().


Regards,

James



On Fri, 2008-06-06 at 11:39 +0200, Stephan Assmus wrote:
> jkim202@xxxxxxxxxxxxxxxxx wrote:
> > Yes, BControls are already part of a BWindow hierarchy.
> > 
> > As François suggested, I tried removing them from the window.
> > 
> > How exactly do you remove BView or BControl object from the window they 
> > belong to?
> > 
> > I tried calling BView::RemoveSelf(), BView::Invalidate(), BView::Flush(), 
> > BView::DetachAll() but they don't seem to do what I expect.
> 
> You need to be more specific, because this should work. From memory, so 
> apply with care:
> 
> BRect originalFrame = someControl->Frame();
> BView* parent = someControl->Parent();
> BView* nextSibling = someControl->NextSibling();
> 
> someControl->RemoveSelf();
> someControl->MoveTo(B_ORIGIN);
> 
> BBitmap* bitmap = new BBitmap(someControl->Frame(), B_RGB32, true);
> bitmap->Lock();
> bitmap->AddChild(someControl);
> someControl->PushState();
> if (someControl->ViewColor() != B_TRANSPARENT_COLOR) {
>       rgb_color highColor = someControl->HighColor();
>       someControl->SetHighColor(someControl->ViewColor());
>       someControl->FillRect(someControl->Bounds());
>       someControl->SetHighColor(highColor);
> }
> someControl->Draw(someControl->Bounds());
> someControl->Sync();
> someControl->PopState();
> someControl->RemoveSelf();
> bitmap->Unlock();
> 
> // you can draw "bitmap" now with the help of any view that is
> // attached to a window
> 
> someControl->MoveTo(originalFrame.LeftTop());
> parent->AddChild(someControl, nextSibling);
> 
> 
> Best regards,
> -Stephan
> 
> 


Other related posts: