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
This commit is contained in:
@@ -50,6 +50,20 @@ struct _BCmdKey{
|
|||||||
BMessage* message;
|
BMessage* message;
|
||||||
BHandler* target;
|
BHandler* target;
|
||||||
int32 targetToken;
|
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
|
#endif // _WINDOWAUX_H
|
||||||
|
|||||||
@@ -225,12 +225,7 @@ BWindow::~BWindow()
|
|||||||
|
|
||||||
noOfItems = accelList.CountItems();
|
noOfItems = accelList.CountItems();
|
||||||
for (int index = noOfItems-1; index >= 0; index--) {
|
for (int index = noOfItems-1; index >= 0; index--) {
|
||||||
_BCmdKey *cmdKey = (_BCmdKey *)accelList.ItemAt(index);
|
delete (_BCmdKey*)accelList.ItemAt(index);
|
||||||
|
|
||||||
accelList.RemoveItem(index);
|
|
||||||
|
|
||||||
delete cmdKey->message;
|
|
||||||
delete cmdKey;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: release other dynamically-allocated objects
|
// TODO: release other dynamically-allocated objects
|
||||||
@@ -1185,7 +1180,8 @@ BWindow::PulseRate() const
|
|||||||
void
|
void
|
||||||
BWindow::AddShortcut(uint32 key, uint32 modifiers, BMenuItem *item)
|
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;
|
modifiers = modifiers | B_COMMAND_KEY;
|
||||||
|
|
||||||
_BCmdKey *cmdKey = new _BCmdKey;
|
_BCmdKey *cmdKey = new _BCmdKey(key, modifiers, msg);
|
||||||
cmdKey->key = key;
|
|
||||||
cmdKey->modifiers = modifiers;
|
|
||||||
cmdKey->message = msg;
|
|
||||||
|
|
||||||
if (target == NULL)
|
if (target)
|
||||||
cmdKey->targetToken = B_ANY_TOKEN;
|
|
||||||
else
|
|
||||||
cmdKey->targetToken = _get_object_token_(target);
|
cmdKey->targetToken = _get_object_token_(target);
|
||||||
|
|
||||||
// removes the shortcut from accelList if it exists!
|
// removes the shortcut from accelList if it exists!
|
||||||
RemoveShortcut(key, modifiers);
|
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);
|
_BCmdKey *cmdKey = (_BCmdKey *)accelList.ItemAt(index);
|
||||||
|
|
||||||
accelList.RemoveItem(index);
|
accelList.RemoveItem(index);
|
||||||
|
|
||||||
delete cmdKey->message;
|
|
||||||
delete cmdKey;
|
delete cmdKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2126,6 +2114,9 @@ BWindow::InitData(BRect frame, const char* title, window_look look,
|
|||||||
fLink->Read<port_id>(&send_port);
|
fLink->Read<port_id>(&send_port);
|
||||||
fLink->SetSendPort(send_port);
|
fLink->SetSendPort(send_port);
|
||||||
|
|
||||||
|
if (locked)
|
||||||
|
be_app->Unlock();
|
||||||
|
|
||||||
STRACE(("Server says that our send port is %ld\n", send_port));
|
STRACE(("Server says that our send port is %ld\n", send_port));
|
||||||
|
|
||||||
STRACE(("Window locked?: %s\n", IsLocked()?"True":"False"));
|
STRACE(("Window locked?: %s\n", IsLocked()?"True":"False"));
|
||||||
|
|||||||
Reference in New Issue
Block a user