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:
parent
9a8540fb4e
commit
4e876d126e
@ -34,8 +34,6 @@
|
|||||||
|
|
||||||
#include <MenuWindow.h>
|
#include <MenuWindow.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#ifndef COMPILE_FOR_R5
|
#ifndef COMPILE_FOR_R5
|
||||||
menu_info BMenu::sMenuInfo;
|
menu_info BMenu::sMenuInfo;
|
||||||
#endif
|
#endif
|
||||||
@ -492,7 +490,7 @@ status_t
|
|||||||
BMenu::SetTargetForItems(BMessenger messenger)
|
BMenu::SetTargetForItems(BMessenger messenger)
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < fItems.CountItems (); i++)
|
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_ERROR;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@ -1063,7 +1061,7 @@ BMenu::_track(int *action, long start)
|
|||||||
if (LockLooper()) {
|
if (LockLooper()) {
|
||||||
GetMouse(&location, &buttons);
|
GetMouse(&location, &buttons);
|
||||||
|
|
||||||
item = HitTestItems(location);
|
item = HitTestItems(location, B_ORIGIN);
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
UnlockLooper();
|
UnlockLooper();
|
||||||
break;
|
break;
|
||||||
@ -1150,6 +1148,13 @@ BMenu::LayoutItems(int32 index)
|
|||||||
ComputeLayout(index, true, true, &width, &height);
|
ComputeLayout(index, true, true, &width, &height);
|
||||||
|
|
||||||
ResizeTo(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1217,8 +1222,17 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
|
|||||||
|
|
||||||
case B_ITEMS_IN_MATRIX:
|
case B_ITEMS_IN_MATRIX:
|
||||||
{
|
{
|
||||||
printf("BMenu: B_ITEMS_IN_MATRIX not yet implemented\n");
|
frame.Set(0, 0, 0, 0);
|
||||||
frame = Frame();
|
|
||||||
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1278,10 +1292,9 @@ void
|
|||||||
BMenu::DrawItems(BRect updateRect)
|
BMenu::DrawItems(BRect updateRect)
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < fItems.CountItems(); i++) {
|
for (int32 i = 0; i < fItems.CountItems(); i++) {
|
||||||
if (ItemAt(i)->Frame().Intersects(updateRect)) {
|
if (ItemAt(i)->Frame().Intersects(updateRect))
|
||||||
ItemAt(i)->Draw();
|
ItemAt(i)->Draw();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Sync();
|
Sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1350,7 +1363,7 @@ BMenu::HitTestItems(BPoint where, BPoint slop) const
|
|||||||
int32 itemCount = CountItems();
|
int32 itemCount = CountItems();
|
||||||
for (int32 i = 0; i < itemCount; i++) {
|
for (int32 i = 0; i < itemCount; i++) {
|
||||||
BMenuItem *item = ItemAt(i);
|
BMenuItem *item = ItemAt(i);
|
||||||
if (item->fBounds.Contains(where))
|
if (item->Frame().Contains(where))
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,6 @@
|
|||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include <AppMisc.h>
|
#include <AppMisc.h>
|
||||||
#include <TokenSpace.h>
|
#include <TokenSpace.h>
|
||||||
|
|
||||||
@ -404,7 +402,6 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
|
|||||||
ulong buttons;
|
ulong buttons;
|
||||||
do {
|
do {
|
||||||
snooze(40000);
|
snooze(40000);
|
||||||
printf("BMenuBar: tracking...\n");
|
|
||||||
GetMouse(&where, &buttons);
|
GetMouse(&where, &buttons);
|
||||||
BMenuItem *menuItem = HitTestItems(where, B_ORIGIN);
|
BMenuItem *menuItem = HitTestItems(where, B_ORIGIN);
|
||||||
if (menuItem) {
|
if (menuItem) {
|
||||||
@ -413,7 +410,6 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
|
|||||||
// all BMenuBar's BMenuItems are BMenus.
|
// all BMenuBar's BMenuItems are BMenus.
|
||||||
BMenu *menu = menuItem->Submenu();
|
BMenu *menu = menuItem->Submenu();
|
||||||
if (menu) {
|
if (menu) {
|
||||||
printf("BMenuBar: showing menu %s\n", menu->Name());
|
|
||||||
do {
|
do {
|
||||||
snooze(40000);
|
snooze(40000);
|
||||||
GetMouse(&where, &buttons);
|
GetMouse(&where, &buttons);
|
||||||
@ -424,12 +420,9 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
resultItem = menu->_track((int *)action, startIndex);
|
resultItem = menu->_track((int *)action, startIndex);
|
||||||
printf("BMenuBar: menu %s: action: %ld\n", menu->Name(), *action);
|
|
||||||
|
|
||||||
// "action" is "5" when the BMenu is closed.
|
// "action" is "5" when the BMenu is closed.
|
||||||
} while (*action != 5);
|
} while (*action != 5);
|
||||||
|
|
||||||
printf("BMenuBar: hiding menu %s\n", menu->Name());
|
|
||||||
}
|
}
|
||||||
SelectItem(NULL);
|
SelectItem(NULL);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
@ -439,10 +432,8 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
|
|||||||
window->Unlock();
|
window->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultItem != NULL) {
|
if (resultItem != NULL)
|
||||||
printf("BMenuBar: selected item %s\n", resultItem->Label());
|
|
||||||
resultItem->Invoke();
|
resultItem->Invoke();
|
||||||
}
|
|
||||||
|
|
||||||
return resultItem;
|
return resultItem;
|
||||||
}
|
}
|
||||||
|
@ -29,11 +29,10 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <Bitmap.h>
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <Message.h>
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
#include <Bitmap.h>
|
|
||||||
|
|
||||||
|
|
||||||
BMenuItem::BMenuItem(const char *label, BMessage *message, char shortcut,
|
BMenuItem::BMenuItem(const char *label, BMessage *message, char shortcut,
|
||||||
@ -107,10 +106,10 @@ BMenuItem::BMenuItem(BMessage *data)
|
|||||||
if (data->FindMessage("_submenu", &subMessage) == B_OK) {
|
if (data->FindMessage("_submenu", &subMessage) == B_OK) {
|
||||||
BArchivable *object = instantiate_object(&subMessage);
|
BArchivable *object = instantiate_object(&subMessage);
|
||||||
|
|
||||||
if (object) {
|
if (object != NULL) {
|
||||||
BMenu *menu = dynamic_cast<BMenu *>(object);
|
BMenu *menu = dynamic_cast<BMenu *>(object);
|
||||||
|
|
||||||
if (menu)
|
if (menu != NULL)
|
||||||
InitMenuData(menu);
|
InitMenuData(menu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,15 +170,15 @@ BMenuItem::~BMenuItem()
|
|||||||
void
|
void
|
||||||
BMenuItem::SetLabel(const char *string)
|
BMenuItem::SetLabel(const char *string)
|
||||||
{
|
{
|
||||||
if (fLabel) {
|
if (fLabel != NULL) {
|
||||||
free(fLabel);
|
free(fLabel);
|
||||||
fLabel = NULL;
|
fLabel = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string)
|
if (string != NULL)
|
||||||
fLabel = strdup(string);
|
fLabel = strdup(string);
|
||||||
|
|
||||||
if (fSuper) {
|
if (fSuper != NULL) {
|
||||||
fSuper->InvalidateLayout();
|
fSuper->InvalidateLayout();
|
||||||
|
|
||||||
if (fSuper->LockLooper()) {
|
if (fSuper->LockLooper()) {
|
||||||
@ -193,13 +192,13 @@ BMenuItem::SetLabel(const char *string)
|
|||||||
void
|
void
|
||||||
BMenuItem::SetEnabled(bool state)
|
BMenuItem::SetEnabled(bool state)
|
||||||
{
|
{
|
||||||
if (fSubmenu)
|
if (fSubmenu != NULL)
|
||||||
fSubmenu->SetEnabled(state);
|
fSubmenu->SetEnabled(state);
|
||||||
|
|
||||||
fEnabled = state;
|
fEnabled = state;
|
||||||
BMenu *menu = Menu();
|
|
||||||
|
|
||||||
if (menu && menu->LockLooper()) {
|
BMenu *menu = Menu();
|
||||||
|
if (menu != NULL && menu->LockLooper()) {
|
||||||
menu->Invalidate(fBounds);
|
menu->Invalidate(fBounds);
|
||||||
menu->UnlockLooper();
|
menu->UnlockLooper();
|
||||||
}
|
}
|
||||||
@ -211,7 +210,7 @@ BMenuItem::SetMarked(bool state)
|
|||||||
{
|
{
|
||||||
fMark = state;
|
fMark = state;
|
||||||
|
|
||||||
if (state && Menu())
|
if (state && Menu() != NULL)
|
||||||
Menu()->ItemMarked(this);
|
Menu()->ItemMarked(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +225,7 @@ BMenuItem::SetTrigger(char ch)
|
|||||||
else
|
else
|
||||||
fSysTrigger = -1;
|
fSysTrigger = -1;
|
||||||
|
|
||||||
if (fSuper)
|
if (fSuper != NULL)
|
||||||
fSuper->InvalidateLayout();
|
fSuper->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,10 +543,8 @@ BMenuItem::Uninstall()
|
|||||||
void
|
void
|
||||||
BMenuItem::SetSuper(BMenu *super)
|
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).");
|
debugger("Error - can't add menu or menu item to more than 1 container (either menu or menubar).");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fSuper = super;
|
fSuper = super;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user