fixed a small problem with StealFocus and RestoreFocus

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18148 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2006-07-14 12:09:49 +00:00
parent 39d02f8967
commit cf2ef43abd
2 changed files with 8 additions and 4 deletions

View File

@ -1174,7 +1174,7 @@ BMenu::InitData(BMessage *data)
data->FindFloat("_maxwidth", &fMaxContentWidth); data->FindFloat("_maxwidth", &fMaxContentWidth);
BMessage msg; BMessage msg;
for (int32 i = 0; data->FindMessage("_items", i, &msg) == B_OK; i++) { for (int32 i = 0; data->FindMessage("_items", i, &msg) == B_OK; i++) {
BArchivable *object = instantiate_object(&msg); BArchivable *object = instantiate_object(&msg);
if (BMenuItem *item = dynamic_cast<BMenuItem *>(object)) { if (BMenuItem *item = dynamic_cast<BMenuItem *>(object)) {
BRect bounds; BRect bounds;

View File

@ -493,6 +493,10 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
void void
BMenuBar::StealFocus() BMenuBar::StealFocus()
{ {
// We already stole the focus, don't do anything
if (fPrevFocusToken != -1)
return;
BWindow *window = Window(); BWindow *window = Window();
if (window != NULL && window->Lock()) { if (window != NULL && window->Lock()) {
BView *focus = window->CurrentFocus(); BView *focus = window->CurrentFocus();
@ -514,12 +518,12 @@ BMenuBar::RestoreFocus()
&& gDefaultTokens.GetToken(fPrevFocusToken, B_HANDLER_TOKEN, (void **)&handler) == B_OK) { && gDefaultTokens.GetToken(fPrevFocusToken, B_HANDLER_TOKEN, (void **)&handler) == B_OK) {
BView *view = dynamic_cast<BView *>(handler); BView *view = dynamic_cast<BView *>(handler);
if (view != NULL && view->Window() == window) if (view != NULL && view->Window() == window)
view->MakeFocus(); view->MakeFocus();
fPrevFocusToken = -1;
} else if (IsFocus()) } else if (IsFocus())
MakeFocus(false); MakeFocus(false);
fPrevFocusToken = -1;
window->Unlock(); window->Unlock();
} }
} }