Fixed a long-standing bug with displaying focus and some tweaks to Desktop focus code

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9809 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm
2004-11-06 16:54:05 +00:00
parent 1d3a392013
commit 929bab19c4
2 changed files with 79 additions and 21 deletions
+48 -16
View File
@@ -327,17 +327,17 @@ void Desktop::MouseEventHandler(int32 code, BPortLink& msg)
{ {
fGeneralLock.Lock(); fGeneralLock.Lock();
rl->fMainLock.Lock(); rl->fMainLock.Lock();
#if 0
printf("Target: %s\n", target->GetName()); STRACE(("Target: %s\n", target->GetName()));
printf("Front: %s\n", ws->FrontLayer()->GetName()); STRACE(("Front: %s\n", ws->FrontLayer()->GetName()));
printf("Focus: %s\n", ws->FocusLayer()->GetName()); STRACE(("Focus: %s\n", ws->FocusLayer()->GetName()));
#endif
if (target != ws->FrontLayer()) WinBorder *previousFocus=NULL;
WinBorder *activeFocus=NULL;
BRegion invalidRegion;
if (target!=ws->FrontLayer())
{ {
WinBorder *previousFocus=NULL;
WinBorder *activeFocus=NULL;
BRegion invalidRegion;
ws->BringToFrontANormalWindow(target); ws->BringToFrontANormalWindow(target);
ws->SearchAndSetNewFront(target); ws->SearchAndSetNewFront(target);
previousFocus = ws->FocusLayer(); previousFocus = ws->FocusLayer();
@@ -351,7 +351,7 @@ printf("Focus: %s\n", ws->FocusLayer()->GetName());
else else
target->MouseDown(evt, false); target->MouseDown(evt, false);
// may be or may be empty. // may or may not be empty.
// TODO: B_MOUSE_DOWN: what if modal of floating windows are in front of us? // TODO: B_MOUSE_DOWN: what if modal of floating windows are in front of us?
invalidRegion.Include(&(activeFocus->fFull)); invalidRegion.Include(&(activeFocus->fFull));
@@ -369,11 +369,10 @@ printf("Focus: %s\n", ws->FocusLayer()->GetName());
} }
fMouseTarget = target; fMouseTarget = target;
#if 0
printf("2Target: %s\n", target->GetName()); STRACE(("2Target: %s\n", target->GetName()));
printf("2Front: %s\n", ws->FrontLayer()->GetName()); STRACE(("2Front: %s\n", ws->FrontLayer()->GetName()));
printf("2Focus: %s\n", ws->FocusLayer()->GetName()); STRACE(("2Focus: %s\n", ws->FocusLayer()->GetName()));
#endif
activeFocus->Window()->Unlock(); activeFocus->Window()->Unlock();
} }
@@ -386,6 +385,39 @@ printf("2Focus: %s\n", ws->FocusLayer()->GetName());
target->MouseDown(evt, true); target->MouseDown(evt, true);
target->Window()->Unlock(); target->Window()->Unlock();
} }
else
{
previousFocus = ws->FocusLayer();
ws->SearchAndSetNewFocus(target);
activeFocus = ws->FocusLayer();
activeFocus->Window()->Lock();
if (target == activeFocus && target->Window()->Flags() & B_WILL_ACCEPT_FIRST_CLICK)
target->MouseDown(evt, true);
else
target->MouseDown(evt, false);
// may or may not be empty.
// TODO: B_MOUSE_DOWN: what if modal of floating windows are in front of us?
invalidRegion.Include(&(activeFocus->fFull));
invalidRegion.Include(&(activeFocus->fTopLayer->fFull));
activeFocus->fParent->RebuildAndForceRedraw(invalidRegion, activeFocus);
if (previousFocus != activeFocus && previousFocus)
{
if (previousFocus->fVisible.CountRects() > 0)
{
invalidRegion.MakeEmpty();
invalidRegion.Include(&(previousFocus->fVisible));
activeFocus->fParent->Invalidate(invalidRegion);
}
}
fMouseTarget = target;
activeFocus->Window()->Unlock();
}
} }
rl->fMainLock.Unlock(); rl->fMainLock.Unlock();
+31 -5
View File
@@ -28,6 +28,8 @@
// This object does not use any locking mechanism. It is designed // This object does not use any locking mechanism. It is designed
// to be used only by RootLayer class. DO NOT USE from another class! // to be used only by RootLayer class. DO NOT USE from another class!
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#include <AppDefs.h>
#include <Message.h>
#include <stdio.h> #include <stdio.h>
#include <Window.h> #include <Window.h>
@@ -1093,7 +1095,7 @@ void Workspace::SearchAndSetNewFocus(WinBorder *preferred)
preferred = fBottomItem? fBottomItem->layerPtr : NULL; preferred = fBottomItem? fBottomItem->layerPtr : NULL;
bool selectOthers = false; bool selectOthers = false;
ListData *item = NULL; ListData *item=NULL;
for(item = fBottomItem; item != NULL; item = item->upperItem) for(item = fBottomItem; item != NULL; item = item->upperItem)
{ {
@@ -1155,10 +1157,34 @@ void Workspace::SearchAndSetNewFocus(WinBorder *preferred)
if(item != fFocusItem) if(item != fFocusItem)
{ {
// TODO: redraw old item in inactive colors & send message to client if(fFocusItem)
// TODO: redraw new item in active colors & send message to client {
// TODO: Rebuild & Redraw. ListData *oldItem=fFocusItem;
fFocusItem = item;
oldItem->layerPtr->HighlightDecorator(false);
BMessage inactive(B_WINDOW_ACTIVATED);
inactive.AddInt64("when",system_time());
inactive.AddBool("active",false);
oldItem->layerPtr->Window()->Lock();
oldItem->layerPtr->Window()->SendMessageToClient(&inactive);
oldItem->layerPtr->Window()->Unlock();
}
fFocusItem=item;
if(fFocusItem)
{
fFocusItem->layerPtr->HighlightDecorator(true);
BMessage active(B_WINDOW_ACTIVATED);
active.AddInt64("when",system_time());
active.AddBool("active",true);
fFocusItem->layerPtr->Window()->Lock();
fFocusItem->layerPtr->Window()->SendMessageToClient(&active);
fFocusItem->layerPtr->Window()->Unlock();
}
} }
} }