Fixed a bad bug in the app_server:

fCurrentLayer was used to determine to which layer a new one would be
added to, but BView::AddChild() would only set this correctly for the
current view, ie. all children of the new child were added to the
wrong layer in the app_server.
Now, AS_LAYER_CREATE sends the parent's token to the server, and the
server relies on this to build the layer hierarchy.
All of a sudden a lot of hidden views are visible now. I noticed the
bug while refactoring the task manager, but a lot of apps were affected.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13164 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-06-16 00:46:02 +00:00
parent 6a6ab9b2e2
commit 53442520cc
3 changed files with 77 additions and 80 deletions
+49 -48
View File
@@ -3558,7 +3558,7 @@ BView::setOwner(BWindow *theOwner)
if (fShelf) if (fShelf)
owner->RemoveHandler(fShelf); owner->RemoveHandler(fShelf);
} }
if (theOwner && theOwner != owner) { if (theOwner && theOwner != owner) {
theOwner->AddHandler(this); theOwner->AddHandler(this);
if (fShelf) if (fShelf)
@@ -3662,17 +3662,17 @@ BView::removeSelf()
void void
BView::callDetachHooks(BView *aView) BView::callDetachHooks(BView *view)
{ {
aView->DetachedFromWindow(); view->DetachedFromWindow();
BView *child = aView->first_child; BView *child = view->first_child;
while (child != NULL) { while (child != NULL) {
aView->callDetachHooks(child); view->callDetachHooks(child);
child = child->next_sibling; child = child->next_sibling;
} }
aView->AllDetached(); view->AllDetached();
} }
@@ -3695,9 +3695,9 @@ BView::removeFromList()
bool bool
BView::addToList(BView *aView, BView *before) BView::addToList(BView *view, BView *before)
{ {
if (!aView) if (!view)
return false; return false;
BView *current = first_child; BView *current = first_child;
@@ -3714,47 +3714,48 @@ BView::addToList(BView *aView, BView *before)
// we're at begining of the list, OR between two elements // we're at begining of the list, OR between two elements
if (current) { if (current) {
if (current == first_child) { if (current == first_child) {
aView->next_sibling = current; view->next_sibling = current;
current->prev_sibling = aView; current->prev_sibling = view;
first_child = aView; first_child = view;
} else { } else {
aView->next_sibling = current; view->next_sibling = current;
aView->prev_sibling = current->prev_sibling; view->prev_sibling = current->prev_sibling;
current->prev_sibling->next_sibling = aView; current->prev_sibling->next_sibling = view;
current->prev_sibling = aView; current->prev_sibling = view;
} }
} else { } else {
// we have reached the end of the list // we have reached the end of the list
// if last!=NULL then we add to the end. Otherwise, aView is the // if last!=NULL then we add to the end. Otherwise, view is the
// first chiild in the list // first chiild in the list
if (last) { if (last) {
last->next_sibling = aView; last->next_sibling = view;
aView->prev_sibling = last; view->prev_sibling = last;
} else } else
first_child = aView; first_child = view;
} }
aView->parent = this; view->parent = this;
return true; return true;
} }
void void
BView::callAttachHooks(BView *aView) BView::callAttachHooks(BView *view)
{ {
aView->AttachedToWindow(); view->AttachedToWindow();
BView *child= aView->first_child; BView *child = view->first_child;
while (child != NULL) { while (child != NULL) {
aView->callAttachHooks(child); view->callAttachHooks(child);
child = child->next_sibling; child = child->next_sibling;
} }
aView->AllAttached(); view->AllAttached();
} }
bool bool
BView::attachView(BView *aView) BView::attachView(BView *view)
{ {
// LEAVE the following line commented!!! // LEAVE the following line commented!!!
// check_lock(); // check_lock();
@@ -3768,30 +3769,30 @@ BView::attachView(BView *aView)
are made. are made.
*/ */
if (aView->top_level_view) if (view->top_level_view)
owner->fLink->StartMessage(AS_LAYER_CREATE_ROOT); owner->fLink->StartMessage(AS_LAYER_CREATE_ROOT);
else else
owner->fLink->StartMessage(AS_LAYER_CREATE); owner->fLink->StartMessage(AS_LAYER_CREATE);
owner->fLink->Attach<int32>(_get_object_token_( aView )); owner->fLink->Attach<int32>(_get_object_token_(view));
owner->fLink->AttachString(aView->Name()); owner->fLink->AttachString(view->Name());
owner->fLink->Attach<BRect>(aView->Frame()); owner->fLink->Attach<BRect>(view->Frame());
owner->fLink->Attach<uint32>(aView->ResizingMode()); owner->fLink->Attach<uint32>(view->ResizingMode());
owner->fLink->Attach<uint32>(aView->fEventMask); owner->fLink->Attach<uint32>(view->fEventMask);
owner->fLink->Attach<uint32>(aView->fEventOptions); owner->fLink->Attach<uint32>(view->fEventOptions);
owner->fLink->Attach<uint32>(aView->Flags()); owner->fLink->Attach<uint32>(view->Flags());
owner->fLink->Attach<bool>(aView->IsHidden(aView)); owner->fLink->Attach<bool>(view->IsHidden(view));
owner->fLink->Attach<rgb_color>(aView->fState->viewColor); owner->fLink->Attach<rgb_color>(view->fState->viewColor);
owner->fLink->Attach<int32>(aView->CountChildren()); owner->fLink->Attach<int32>(_get_object_token_(this));
owner->fLink->Flush(); owner->fLink->Flush();
aView->setCachedState(); view->setCachedState();
// we attach all its children // we attach all its children
BView *child= aView->first_child; BView *child = view->first_child;
while (child != NULL) { while (child != NULL) {
aView->attachView(child); view->attachView(child);
child = child->next_sibling; child = child->next_sibling;
} }
@@ -3802,26 +3803,26 @@ BView::attachView(BView *aView)
void void
BView::deleteView( BView* aView) BView::deleteView(BView* view)
{ {
BView *child = aView->first_child; BView *child = view->first_child;
while (child != NULL) { while (child != NULL) {
BView *nextChild = child->next_sibling; BView *nextChild = child->next_sibling;
deleteView(child); deleteView(child);
child = nextChild; child = nextChild;
} }
delete aView; delete view;
} }
BView * BView *
BView::findView(const BView *aView, const char *viewName) const BView::findView(const BView *view, const char *viewName) const
{ {
if (!strcmp(viewName, aView->Name())) if (!strcmp(viewName, view->Name()))
return const_cast<BView *>(aView); return const_cast<BView *>(view);
BView *child = aView->first_child; BView *child = view->first_child;
while (child != NULL) { while (child != NULL) {
BView *view; BView *view;
if ((view = findView(child, viewName)) != NULL) if ((view = findView(child, viewName)) != NULL)
+27 -30
View File
@@ -313,7 +313,7 @@ ServerWindow::SetLayerState(Layer *layer, BPrivate::LinkReceiver &link)
inline Layer* inline Layer*
ServerWindow::CreateLayerTree(Layer *localRoot, BPrivate::LinkReceiver &link) ServerWindow::CreateLayerTree(BPrivate::LinkReceiver &link, Layer **_parent)
{ {
// NOTE: no need to check for a lock. This is a private method. // NOTE: no need to check for a lock. This is a private method.
@@ -324,7 +324,7 @@ ServerWindow::CreateLayerTree(Layer *localRoot, BPrivate::LinkReceiver &link)
uint32 eventOptions; uint32 eventOptions;
uint32 flags; uint32 flags;
bool hidden; bool hidden;
int32 childCount; int32 parentToken;
char *name = NULL; char *name = NULL;
rgb_color viewColor; rgb_color viewColor;
@@ -336,10 +336,11 @@ ServerWindow::CreateLayerTree(Layer *localRoot, BPrivate::LinkReceiver &link)
link.Read<uint32>(&eventOptions); link.Read<uint32>(&eventOptions);
link.Read<uint32>(&flags); link.Read<uint32>(&flags);
link.Read<bool>(&hidden); link.Read<bool>(&hidden);
link.Read<rgb_color>(&viewColor ); link.Read<rgb_color>(&viewColor);
link.Read<int32>(&childCount); link.Read<int32>(&parentToken);
STRACE(("ServerWindow(%s)::CreateLayerTree()-> layer %s, token %ld\n", fName,name,token)); STRACE(("ServerWindow(%s)::CreateLayerTree()-> layer %s, token %ld\n",
fName, name, token));
Layer *newLayer = new Layer(frame, name, token, resizeMask, Layer *newLayer = new Layer(frame, name, token, resizeMask,
flags, gDesktop->GetDisplayDriver()); flags, gDesktop->GetDisplayDriver());
@@ -353,9 +354,13 @@ ServerWindow::CreateLayerTree(Layer *localRoot, BPrivate::LinkReceiver &link)
newLayer->fEventOptions = eventOptions; newLayer->fEventOptions = eventOptions;
newLayer->fOwner = fWinBorder; newLayer->fOwner = fWinBorder;
// add the new Layer to the tree structure. if (_parent) {
if (localRoot) Layer *parent = fWinBorder->FindLayer(parentToken);
localRoot->AddChild(newLayer, NULL); if (parent == NULL)
CRITICAL("View token not found!\n");
*_parent = parent;
}
return newLayer; return newLayer;
} }
@@ -364,7 +369,7 @@ ServerWindow::CreateLayerTree(Layer *localRoot, BPrivate::LinkReceiver &link)
void void
ServerWindow::DispatchMessage(int32 code, BPrivate::LinkReceiver &link) ServerWindow::DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
{ {
if (fCurrentLayer == NULL && code != AS_LAYER_CREATE_ROOT) { if (fCurrentLayer == NULL && code != AS_LAYER_CREATE_ROOT && code != AS_LAYER_CREATE) {
printf("ServerWindow %s received unexpected code - message offset %ld before top_view attached.\n",fName, code - SERVER_TRUE); printf("ServerWindow %s received unexpected code - message offset %ld before top_view attached.\n",fName, code - SERVER_TRUE);
return; return;
} }
@@ -431,22 +436,19 @@ ServerWindow::DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
int32 token; int32 token;
link.Read<int32>(&token); link.Read<int32>(&token);
// Layer *current = FindLayer(fWinBorder->fTopLayer, token);
Layer *current = fWinBorder->FindLayer(token); Layer *current = fWinBorder->FindLayer(token);
if(current) if (current) {
{
DTRACE(("ServerWindow %s: Message AS_SET_CURRENT_LAYER: %s, token %ld\n", fName, current->fName->String(), token)); DTRACE(("ServerWindow %s: Message AS_SET_CURRENT_LAYER: %s, token %ld\n", fName, current->fName->String(), token));
} } else {
else
{
DTRACE(("ServerWindow %s: Message AS_SET_CURRENT_LAYER: layer not found, token %ld\n", fName, token)); DTRACE(("ServerWindow %s: Message AS_SET_CURRENT_LAYER: layer not found, token %ld\n", fName, token));
} }
if (current) if (current)
fCurrentLayer=current; fCurrentLayer = current;
else // hope this NEVER happens! :-) else // hope this NEVER happens! :-)
CRITICAL("Server PANIC: window cannot find Layer with ID\n"); CRITICAL("Server PANIC: window cannot find Layer with ID\n");
// ToDo: if this happens, we probably want to kill the app and clean up
break; break;
} }
@@ -458,9 +460,8 @@ ServerWindow::DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// This should be the *only* place where this happens. // This should be the *only* place where this happens.
if (fCurrentLayer != NULL) if (fCurrentLayer != NULL)
break; break;
// fWinBorder->fTopLayer = CreateLayerTree(NULL); fWinBorder->fTopLayer = CreateLayerTree(link, NULL);
fWinBorder->fTopLayer = CreateLayerTree(NULL, link);
fWinBorder->fTopLayer->SetAsTopLayer(true); fWinBorder->fTopLayer->SetAsTopLayer(true);
fCurrentLayer = fWinBorder->fTopLayer; fCurrentLayer = fWinBorder->fTopLayer;
@@ -472,19 +473,15 @@ ServerWindow::DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
case AS_LAYER_CREATE: case AS_LAYER_CREATE:
{ {
STRACE(("ServerWindow %s: Message AS_LAYER_CREATE: Layer name: %s\n", fName, fCurrentLayer->fName->String())); STRACE(("ServerWindow %s: Message AS_LAYER_CREATE: Layer name: %s\n", fName, fCurrentLayer->fName->String()));
Layer *newLayer;
if (fCurrentLayer == NULL)
break;
// newLayer = CreateLayerTree(NULL); Layer* parent = NULL;
newLayer = CreateLayerTree(NULL, link); Layer* newLayer = CreateLayerTree(link, &parent);
fCurrentLayer->AddChild(newLayer, this); if (parent != NULL)
parent->AddChild(newLayer, this);
if (!(newLayer->IsHidden())){ if (!newLayer->IsHidden()) {
myRootLayer->GoInvalidate(newLayer, newLayer->fFull); myRootLayer->GoInvalidate(newLayer, newLayer->fFull);
} }
break; break;
} }
case AS_LAYER_DELETE: case AS_LAYER_DELETE:
@@ -512,7 +509,7 @@ ServerWindow::DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
delete fCurrentLayer; delete fCurrentLayer;
fCurrentLayer=parent; fCurrentLayer = parent;
break; break;
} }
case AS_LAYER_SET_STATE: case AS_LAYER_SET_STATE:
+1 -2
View File
@@ -117,9 +117,8 @@ public:
FMWList fWinFMWList; FMWList fWinFMWList;
private: private:
// methods for retrieving and creating a tree strcture of Layers. // methods for retrieving and creating a tree strcture of Layers.
Layer* CreateLayerTree(Layer *localRoot, BPrivate::LinkReceiver &link); Layer* CreateLayerTree(BPrivate::LinkReceiver &link, Layer **_parent);
void SetLayerState(Layer *layer, BPrivate::LinkReceiver &link); void SetLayerState(Layer *layer, BPrivate::LinkReceiver &link);
void SetLayerFontState(Layer *layer, BPrivate::LinkReceiver &link); void SetLayerFontState(Layer *layer, BPrivate::LinkReceiver &link);
void ClientDied(bool crashed); void ClientDied(bool crashed);