From 442992bf26284b4cb771ead1332124f3502e4781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 7 Jun 2005 13:19:28 +0000 Subject: [PATCH] fixed some pretty bad bugs that prevented menus from working (they now do): The BMessage* in AddShortcut is taken in responsibility by the BWindow, so we cannot directly use the message from BMenuItem, the be_app was locked in InitData but never unlocked, it fixes BMenus only working once, and who knows what else it fixes. A little cleanup with _BCmdKey usage, also note that it is inefficient to RemoveItem()s from a list in the destructor of any class using a BList as data container! Simply delete the items and be done with it. The BList destructor will take care of the rest and free its storage in one go. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12982 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/interface/WindowAux.h | 14 ++++++++++++++ src/kits/interface/Window.cpp | 27 +++++++++------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/headers/private/interface/WindowAux.h b/headers/private/interface/WindowAux.h index 199690a82d..8174a2ec9b 100644 --- a/headers/private/interface/WindowAux.h +++ b/headers/private/interface/WindowAux.h @@ -50,6 +50,20 @@ struct _BCmdKey{ BMessage* message; BHandler* target; int32 targetToken; + + _BCmdKey(uint32 k, uint32 mod, BMessage* m = NULL) + : key(k), + modifiers(mod), + message(m), + target(NULL), + targetToken(B_ANY_TOKEN) + { + } + ~_BCmdKey() + { + delete message; + } + }; #endif // _WINDOWAUX_H diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index 1ec5a54986..fabeab87eb 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -225,12 +225,7 @@ BWindow::~BWindow() noOfItems = accelList.CountItems(); for (int index = noOfItems-1; index >= 0; index--) { - _BCmdKey *cmdKey = (_BCmdKey *)accelList.ItemAt(index); - - accelList.RemoveItem(index); - - delete cmdKey->message; - delete cmdKey; + delete (_BCmdKey*)accelList.ItemAt(index); } // TODO: release other dynamically-allocated objects @@ -1185,7 +1180,8 @@ BWindow::PulseRate() const void BWindow::AddShortcut(uint32 key, uint32 modifiers, BMenuItem *item) { - AddShortcut(key, modifiers, item->Message(), this); + if (item->Message()) + AddShortcut(key, modifiers, new BMessage(*item->Message()), this); } @@ -1212,21 +1208,15 @@ BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage *msg, BHandler *targ modifiers = modifiers | B_COMMAND_KEY; - _BCmdKey *cmdKey = new _BCmdKey; - cmdKey->key = key; - cmdKey->modifiers = modifiers; - cmdKey->message = msg; + _BCmdKey *cmdKey = new _BCmdKey(key, modifiers, msg); - if (target == NULL) - cmdKey->targetToken = B_ANY_TOKEN; - else + if (target) cmdKey->targetToken = _get_object_token_(target); // removes the shortcut from accelList if it exists! RemoveShortcut(key, modifiers); - accelList.AddItem(cmdKey); - + accelList.AddItem((void*)cmdKey); } @@ -1239,8 +1229,6 @@ BWindow::RemoveShortcut(uint32 key, uint32 modifiers) _BCmdKey *cmdKey = (_BCmdKey *)accelList.ItemAt(index); accelList.RemoveItem(index); - - delete cmdKey->message; delete cmdKey; } } @@ -2126,6 +2114,9 @@ BWindow::InitData(BRect frame, const char* title, window_look look, fLink->Read(&send_port); fLink->SetSendPort(send_port); + if (locked) + be_app->Unlock(); + STRACE(("Server says that our send port is %ld\n", send_port)); STRACE(("Window locked?: %s\n", IsLocked()?"True":"False"));