Now BMenu also calculate the triggers for BMenuItems.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10827 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2005-01-18 10:42:41 +00:00
parent 93e11ddfc8
commit 727e24f793
1 changed files with 42 additions and 0 deletions

View File

@ -1498,12 +1498,54 @@ BMenu::IsStickyMode() const
void
BMenu::CalcTriggers()
{
BList triggersList;
// Gathers the existing triggers
// TODO: Oh great, reinterpret_cast.
for (int32 i = 0; i < CountItems(); i++) {
char trigger = ItemAt(i)->Trigger();
if (trigger != 0)
triggersList.AddItem(reinterpret_cast<void *>((uint32)trigger));
}
// Set triggers for items which don't have one yet
for (int32 i = 0; i < CountItems(); i++) {
BMenuItem *item = ItemAt(i);
if (item->Trigger() == 0) {
const char *newTrigger = ChooseTrigger(item->Label(), &triggersList);
if (newTrigger != NULL) {
item->SetSysTrigger(*newTrigger);
// TODO: This is crap. I'd prefer to have
// BMenuItem::SetSysTrigger(const char *) update fTriggerIndex.
// This isn't the case on beos, but it will probably be like that on haiku.
item->fTriggerIndex = newTrigger - item->Label();
}
}
}
}
const char *
BMenu::ChooseTrigger(const char *title, BList *chars)
{
ASSERT(chars != NULL);
if (title == NULL)
return NULL;
char *titlePtr = const_cast<char *>(title);
char trigger;
// TODO: Oh great, reinterpret_cast all around
while ((trigger = *titlePtr) != '\0') {
if (!chars->HasItem(reinterpret_cast<void *>((uint32)trigger))) {
chars->AddItem(reinterpret_cast<void *>((uint32)trigger));
return titlePtr;
}
titlePtr++;
}
return NULL;
}