implemented B_ITEMS_IN_MATRIX layout correctly. Small cleanups all around.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10571 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2005-01-03 13:33:03 +00:00
parent 9a8540fb4e
commit 4e876d126e
3 changed files with 40 additions and 39 deletions

View File

@ -34,8 +34,6 @@
#include <MenuWindow.h>
#include <stdio.h>
#ifndef COMPILE_FOR_R5
menu_info BMenu::sMenuInfo;
#endif
@ -492,7 +490,7 @@ status_t
BMenu::SetTargetForItems(BMessenger messenger)
{
for (int32 i = 0; i < fItems.CountItems (); i++)
if (((BMenuItem*)fItems.ItemAt(i))->SetTarget(messenger) != B_OK)
if (ItemAt(i)->SetTarget(messenger) != B_OK)
return B_ERROR;
return B_OK;
@ -1034,7 +1032,7 @@ BMenu::_show(bool selectFirstItem)
point.x + 20, point.y + 200), this);
window->Show();
return true;
}
@ -1063,7 +1061,7 @@ BMenu::_track(int *action, long start)
if (LockLooper()) {
GetMouse(&location, &buttons);
item = HitTestItems(location);
item = HitTestItems(location, B_ORIGIN);
if (item == NULL) {
UnlockLooper();
break;
@ -1150,6 +1148,13 @@ BMenu::LayoutItems(int32 index)
ComputeLayout(index, true, true, &width, &height);
ResizeTo(width, height);
// TODO: Looks like this call is needed when the layout is
// B_ITEMS_IN_MATRIX, otherwise the view is placed in a wrong place
// (by the above call). See if we can avoid this by being
// smarter in other places.
if (fLayout == B_ITEMS_IN_MATRIX)
MoveTo(B_ORIGIN);
}
@ -1160,7 +1165,7 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
BRect frame;
float iWidth, iHeight;
BMenuItem *item;
switch (fLayout) {
case B_ITEMS_IN_COLUMN:
{
@ -1217,11 +1222,20 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
case B_ITEMS_IN_MATRIX:
{
printf("BMenu: B_ITEMS_IN_MATRIX not yet implemented\n");
frame = Frame();
frame.Set(0, 0, 0, 0);
for (int32 i = 0; i < CountItems(); i++) {
BMenuItem *item = ItemAt(i);
if (item != NULL) {
frame.left = min_c(frame.left, item->Frame().left);
frame.right = max_c(frame.right, item->Frame().right);
frame.top = min_c(frame.top, item->Frame().top);
frame.bottom = max_c(frame.bottom, item->Frame().bottom);
}
}
break;
}
default:
break;
}
@ -1278,9 +1292,8 @@ void
BMenu::DrawItems(BRect updateRect)
{
for (int32 i = 0; i < fItems.CountItems(); i++) {
if (ItemAt(i)->Frame().Intersects(updateRect)) {
if (ItemAt(i)->Frame().Intersects(updateRect))
ItemAt(i)->Draw();
}
}
Sync();
}
@ -1350,7 +1363,7 @@ BMenu::HitTestItems(BPoint where, BPoint slop) const
int32 itemCount = CountItems();
for (int32 i = 0; i < itemCount; i++) {
BMenuItem *item = ItemAt(i);
if (item->fBounds.Contains(where))
if (item->Frame().Contains(where))
return item;
}

View File

@ -32,8 +32,6 @@
#include <MenuItem.h>
#include <Window.h>
#include <stdio.h>
#include <AppMisc.h>
#include <TokenSpace.h>
@ -404,7 +402,6 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
ulong buttons;
do {
snooze(40000);
printf("BMenuBar: tracking...\n");
GetMouse(&where, &buttons);
BMenuItem *menuItem = HitTestItems(where, B_ORIGIN);
if (menuItem) {
@ -413,7 +410,6 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
// all BMenuBar's BMenuItems are BMenus.
BMenu *menu = menuItem->Submenu();
if (menu) {
printf("BMenuBar: showing menu %s\n", menu->Name());
do {
snooze(40000);
GetMouse(&where, &buttons);
@ -424,12 +420,9 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
break;
resultItem = menu->_track((int *)action, startIndex);
printf("BMenuBar: menu %s: action: %ld\n", menu->Name(), *action);
// "action" is "5" when the BMenu is closed.
} while (*action != 5);
printf("BMenuBar: hiding menu %s\n", menu->Name());
}
SelectItem(NULL);
Invalidate();
@ -439,10 +432,8 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
window->Unlock();
}
if (resultItem != NULL) {
printf("BMenuBar: selected item %s\n", resultItem->Label());
if (resultItem != NULL)
resultItem->Invoke();
}
return resultItem;
}

View File

@ -29,11 +29,10 @@
#include <string.h>
#include <stdlib.h>
#include <Bitmap.h>
#include <MenuItem.h>
#include <String.h>
#include <Message.h>
#include <Window.h>
#include <Bitmap.h>
BMenuItem::BMenuItem(const char *label, BMessage *message, char shortcut,
@ -107,10 +106,10 @@ BMenuItem::BMenuItem(BMessage *data)
if (data->FindMessage("_submenu", &subMessage) == B_OK) {
BArchivable *object = instantiate_object(&subMessage);
if (object) {
BMenu *menu = dynamic_cast<BMenu*>(object);
if (object != NULL) {
BMenu *menu = dynamic_cast<BMenu *>(object);
if (menu)
if (menu != NULL)
InitMenuData(menu);
}
}
@ -171,15 +170,15 @@ BMenuItem::~BMenuItem()
void
BMenuItem::SetLabel(const char *string)
{
if (fLabel) {
if (fLabel != NULL) {
free(fLabel);
fLabel = NULL;
}
if (string)
if (string != NULL)
fLabel = strdup(string);
if (fSuper) {
if (fSuper != NULL) {
fSuper->InvalidateLayout();
if (fSuper->LockLooper()) {
@ -193,13 +192,13 @@ BMenuItem::SetLabel(const char *string)
void
BMenuItem::SetEnabled(bool state)
{
if (fSubmenu)
if (fSubmenu != NULL)
fSubmenu->SetEnabled(state);
fEnabled = state;
BMenu *menu = Menu();
if (menu && menu->LockLooper()) {
if (menu != NULL && menu->LockLooper()) {
menu->Invalidate(fBounds);
menu->UnlockLooper();
}
@ -211,7 +210,7 @@ BMenuItem::SetMarked(bool state)
{
fMark = state;
if (state && Menu())
if (state && Menu() != NULL)
Menu()->ItemMarked(this);
}
@ -226,7 +225,7 @@ BMenuItem::SetTrigger(char ch)
else
fSysTrigger = -1;
if (fSuper)
if (fSuper != NULL)
fSuper->InvalidateLayout();
}
@ -544,11 +543,9 @@ BMenuItem::Uninstall()
void
BMenuItem::SetSuper(BMenu *super)
{
if (fSuper != NULL && super != NULL) {
if (fSuper != NULL && super != NULL)
debugger("Error - can't add menu or menu item to more than 1 container (either menu or menubar).");
return;
}
fSuper = super;
if (fSubmenu)