* Cleanup, no functional change.

* Remove superfluous operator=() implementations.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32174 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-08-07 08:01:27 +00:00
parent d82ea8abda
commit 50f8cd14bb
6 changed files with 320 additions and 319 deletions
+15 -14
View File
@@ -1,34 +1,36 @@
/* /*
* Copyright 2006-2008, Haiku, Inc. All Rights Reserved. * Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _MENU_FIELD_H #ifndef _MENU_FIELD_H
#define _MENU_FIELD_H #define _MENU_FIELD_H
#include <BeBuild.h> #include <BeBuild.h>
#include <Menu.h> /* For convenience */ #include <Menu.h>
#include <View.h> #include <View.h>
class BMenuBar; class BMenuBar;
class BMenuField : public BView { class BMenuField : public BView {
public: public:
BMenuField(BRect frame, const char* name, BMenuField(BRect frame, const char* name,
const char* label, BMenu* menu, const char* label, BMenu* menu,
uint32 resize = B_FOLLOW_LEFT|B_FOLLOW_TOP, uint32 resize = B_FOLLOW_LEFT|B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE); uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
BMenuField(BRect frame, const char* name, BMenuField(BRect frame, const char* name,
const char* label, BMenu* menu, const char* label, BMenu* menu,
bool fixed_size, bool fixed_size,
uint32 resize = B_FOLLOW_LEFT|B_FOLLOW_TOP, uint32 resize = B_FOLLOW_LEFT|B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE); uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
BMenuField(const char* name, BMenuField(const char* name,
const char* label, BMenu* menu, const char* label, BMenu* menu,
BMessage* message, BMessage* message,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE); uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
BMenuField(const char* label, BMenuField(const char* label,
BMenu* menu, BMessage* message = NULL); BMenu* menu, BMessage* message = NULL);
BMenuField(BMessage* data); BMenuField(BMessage* data);
virtual ~BMenuField(); virtual ~BMenuField();
@@ -57,7 +59,7 @@ class BMenuField : public BView {
virtual void SetLabel(const char* label); virtual void SetLabel(const char* label);
const char* Label() const; const char* Label() const;
virtual void SetEnabled(bool on); virtual void SetEnabled(bool on);
bool IsEnabled() const; bool IsEnabled() const;
@@ -86,7 +88,7 @@ class BMenuField : public BView {
BLayoutItem* CreateLabelLayoutItem(); BLayoutItem* CreateLabelLayoutItem();
BLayoutItem* CreateMenuBarLayoutItem(); BLayoutItem* CreateMenuBarLayoutItem();
/*----- Private or reserved -----------------------------------------*/ /*----- Private or reserved -----------------------------------------*/
virtual status_t Perform(perform_code d, void* arg); virtual status_t Perform(perform_code d, void* arg);
@@ -107,17 +109,16 @@ private:
virtual void _ReservedMenuField2(); virtual void _ReservedMenuField2();
virtual void _ReservedMenuField3(); virtual void _ReservedMenuField3();
BMenuField &operator=(const BMenuField&); BMenuField& operator=(const BMenuField& other);
void InitObject(const char* label); void InitObject(const char* label);
void InitObject2(); void InitObject2();
void DrawLabel(BRect bounds, BRect update); void DrawLabel(BRect bounds, BRect update);
static void InitMenu(BMenu* menu); static void InitMenu(BMenu* menu);
int32 _MenuTask(); int32 _MenuTask();
static int32 _thread_entry(void *arg); static int32 _thread_entry(void *arg);
void _UpdateFrame(); void _UpdateFrame();
void _InitMenuBar(BMenu* menu, void _InitMenuBar(BMenu* menu,
BRect frame, bool fixedSize); BRect frame, bool fixedSize);
+10 -24
View File
@@ -22,7 +22,7 @@
#include <Window.h> #include <Window.h>
_BMCFilter_::_BMCFilter_(BMenuField *menuField, uint32 what) _BMCFilter_::_BMCFilter_(BMenuField* menuField, uint32 what)
: :
BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, what), BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, what),
fMenuField(menuField) fMenuField(menuField)
@@ -36,10 +36,10 @@ _BMCFilter_::~_BMCFilter_()
filter_result filter_result
_BMCFilter_::Filter(BMessage *message, BHandler **handler) _BMCFilter_::Filter(BMessage* message, BHandler** handler)
{ {
if (message->what == B_MOUSE_DOWN) { if (message->what == B_MOUSE_DOWN) {
if (BView *view = dynamic_cast<BView *>(*handler)) { if (BView* view = dynamic_cast<BView*>(*handler)) {
BPoint point; BPoint point;
message->FindPoint("be:view_where", &point); message->FindPoint("be:view_where", &point);
view->ConvertToParent(&point); view->ConvertToParent(&point);
@@ -52,13 +52,6 @@ _BMCFilter_::Filter(BMessage *message, BHandler **handler)
} }
_BMCFilter_ &
_BMCFilter_::operator=(const _BMCFilter_ &)
{
return *this;
}
// #pragma mark - // #pragma mark -
@@ -87,7 +80,7 @@ _BMCMenuBar_::_BMCMenuBar_(bool fixedSize, BMenuField* menuField)
} }
_BMCMenuBar_::_BMCMenuBar_(BMessage *data) _BMCMenuBar_::_BMCMenuBar_(BMessage* data)
: BMenuBar(data), : BMenuBar(data),
fMenuField(NULL), fMenuField(NULL),
fFixedSize(true), fFixedSize(true),
@@ -108,8 +101,8 @@ _BMCMenuBar_::~_BMCMenuBar_()
} }
BArchivable * BArchivable*
_BMCMenuBar_::Instantiate(BMessage *data) _BMCMenuBar_::Instantiate(BMessage* data)
{ {
if (validate_instantiation(data, "_BMCMenuBar_")) if (validate_instantiation(data, "_BMCMenuBar_"))
return new _BMCMenuBar_(data); return new _BMCMenuBar_(data);
@@ -121,10 +114,10 @@ _BMCMenuBar_::Instantiate(BMessage *data)
void void
_BMCMenuBar_::AttachedToWindow() _BMCMenuBar_::AttachedToWindow()
{ {
fMenuField = static_cast<BMenuField *>(Parent()); fMenuField = static_cast<BMenuField*>(Parent());
// Don't cause the KeyMenuBar to change by being attached // Don't cause the KeyMenuBar to change by being attached
BMenuBar *menuBar = Window()->KeyMenuBar(); BMenuBar* menuBar = Window()->KeyMenuBar();
BMenuBar::AttachedToWindow(); BMenuBar::AttachedToWindow();
Window()->SetKeyMenuBar(menuBar); Window()->SetKeyMenuBar(menuBar);
@@ -307,12 +300,12 @@ _BMCMenuBar_::FrameResized(float width, float height)
void void
_BMCMenuBar_::MessageReceived(BMessage *msg) _BMCMenuBar_::MessageReceived(BMessage* msg)
{ {
switch (msg->what) { switch (msg->what) {
case 'TICK': case 'TICK':
{ {
BMenuItem *item = ItemAt(0); BMenuItem* item = ItemAt(0);
if (item && item->Submenu() && item->Submenu()->Window()) { if (item && item->Submenu() && item->Submenu()->Window()) {
BMessage message(B_KEY_DOWN); BMessage message(B_KEY_DOWN);
@@ -389,13 +382,6 @@ _BMCMenuBar_::MaxSize()
} }
_BMCMenuBar_
&_BMCMenuBar_::operator=(const _BMCMenuBar_ &)
{
return *this;
}
void void
_BMCMenuBar_::_Init(bool setMaxContentWidth) _BMCMenuBar_::_Init(bool setMaxContentWidth)
{ {
+143 -144
View File
@@ -8,6 +8,7 @@
* Rene Gollent ([email protected]) * Rene Gollent ([email protected])
*/ */
#include <Menu.h> #include <Menu.h>
#include <new> #include <new>
@@ -65,10 +66,10 @@ private:
class ExtraMenuData { class ExtraMenuData {
public: public:
menu_tracking_hook trackingHook; menu_tracking_hook trackingHook;
void *trackingState; void* trackingState;
ExtraMenuData(menu_tracking_hook func, void *state) ExtraMenuData(menu_tracking_hook func, void* state)
{ {
trackingHook = func; trackingHook = func;
trackingState = state; trackingState = state;
@@ -173,7 +174,7 @@ static property_info sPropList[] = {
}; };
const char *BPrivate::kEmptyMenuLabel = "<empty>"; const char* BPrivate::kEmptyMenuLabel = "<empty>";
struct BMenu::LayoutData { struct BMenu::LayoutData {
@@ -182,7 +183,7 @@ struct BMenu::LayoutData {
}; };
BMenu::BMenu(const char *name, menu_layout layout) BMenu::BMenu(const char* name, menu_layout layout)
: BView(BRect(0, 0, 0, 0), name, 0, B_WILL_DRAW), : BView(BRect(0, 0, 0, 0), name, 0, B_WILL_DRAW),
fChosenItem(NULL), fChosenItem(NULL),
fPad(14.0f, 2.0f, 20.0f, 0.0f), fPad(14.0f, 2.0f, 20.0f, 0.0f),
@@ -216,7 +217,7 @@ BMenu::BMenu(const char *name, menu_layout layout)
} }
BMenu::BMenu(const char *name, float width, float height) BMenu::BMenu(const char* name, float width, float height)
: BView(BRect(0.0f, width, 0.0f, height), name, 0, B_WILL_DRAW), : BView(BRect(0.0f, width, 0.0f, height), name, 0, B_WILL_DRAW),
fChosenItem(NULL), fChosenItem(NULL),
fSelected(NULL), fSelected(NULL),
@@ -261,7 +262,7 @@ BMenu::~BMenu()
} }
BMenu::BMenu(BMessage *archive) BMenu::BMenu(BMessage* archive)
: BView(archive), : BView(archive),
fChosenItem(NULL), fChosenItem(NULL),
fPad(14.0f, 2.0f, 20.0f, 0.0f), fPad(14.0f, 2.0f, 20.0f, 0.0f),
@@ -306,7 +307,7 @@ BMenu::Instantiate(BMessage* archive)
status_t status_t
BMenu::Archive(BMessage *data, bool deep) const BMenu::Archive(BMessage* data, bool deep) const
{ {
status_t err = BView::Archive(data, deep); status_t err = BView::Archive(data, deep);
@@ -325,7 +326,7 @@ BMenu::Archive(BMessage *data, bool deep) const
if (err == B_OK) if (err == B_OK)
err = data->AddFloat("_maxwidth", fMaxContentWidth); err = data->AddFloat("_maxwidth", fMaxContentWidth);
if (err == B_OK && deep) { if (err == B_OK && deep) {
BMenuItem *item = NULL; BMenuItem* item = NULL;
int32 index = 0; int32 index = 0;
while ((item = ItemAt(index++)) != NULL) { while ((item = ItemAt(index++)) != NULL) {
BMessage itemData; BMessage itemData;
@@ -353,17 +354,17 @@ BMenu::AttachedToWindow()
// when called there. Probably because the BApplication isn't yet // when called there. Probably because the BApplication isn't yet
// initialized, or running. // initialized, or running.
BMenu::sAltAsCommandKey = true; BMenu::sAltAsCommandKey = true;
key_map *keys = NULL; key_map* keys = NULL;
char *chars = NULL; char* chars = NULL;
get_key_map(&keys, &chars); get_key_map(&keys, &chars);
if (keys == NULL || keys->left_command_key != 0x5d if (keys == NULL || keys->left_command_key != 0x5d
|| keys->left_control_key != 0x5c) || keys->left_control_key != 0x5c)
BMenu::sAltAsCommandKey = false; BMenu::sAltAsCommandKey = false;
free(chars); free(chars);
free(keys); free(keys);
BMenuItem *superItem = Superitem(); BMenuItem* superItem = Superitem();
BMenu *superMenu = Supermenu(); BMenu* superMenu = Supermenu();
if (AddDynamicItem(B_INITIAL_ADD)) { if (AddDynamicItem(B_INITIAL_ADD)) {
do { do {
if (superMenu != NULL && !superMenu->_OkToProceed(superItem)) { if (superMenu != NULL && !superMenu->_OkToProceed(superItem)) {
@@ -390,18 +391,19 @@ BMenu::DetachedFromWindow()
bool bool
BMenu::AddItem(BMenuItem *item) BMenu::AddItem(BMenuItem* item)
{ {
return AddItem(item, CountItems()); return AddItem(item, CountItems());
} }
bool bool
BMenu::AddItem(BMenuItem *item, int32 index) BMenu::AddItem(BMenuItem* item, int32 index)
{ {
if (fLayout == B_ITEMS_IN_MATRIX) if (fLayout == B_ITEMS_IN_MATRIX) {
debugger("BMenu::AddItem(BMenuItem *, int32) this method can only " debugger("BMenu::AddItem(BMenuItem*, int32) this method can only "
"be called if the menu layout is not B_ITEMS_IN_MATRIX"); "be called if the menu layout is not B_ITEMS_IN_MATRIX");
}
if (!item || !_AddItem(item, index)) if (!item || !_AddItem(item, index))
return false; return false;
@@ -420,11 +422,12 @@ BMenu::AddItem(BMenuItem *item, int32 index)
bool bool
BMenu::AddItem(BMenuItem *item, BRect frame) BMenu::AddItem(BMenuItem* item, BRect frame)
{ {
if (fLayout != B_ITEMS_IN_MATRIX) if (fLayout != B_ITEMS_IN_MATRIX) {
debugger("BMenu::AddItem(BMenuItem *, BRect) this method can only " debugger("BMenu::AddItem(BMenuItem*, BRect) this method can only "
"be called if the menu layout is B_ITEMS_IN_MATRIX"); "be called if the menu layout is B_ITEMS_IN_MATRIX");
}
if (!item) if (!item)
return false; return false;
@@ -449,9 +452,9 @@ BMenu::AddItem(BMenuItem *item, BRect frame)
bool bool
BMenu::AddItem(BMenu *submenu) BMenu::AddItem(BMenu* submenu)
{ {
BMenuItem *item = new (nothrow) BMenuItem(submenu); BMenuItem* item = new (nothrow) BMenuItem(submenu);
if (!item) if (!item)
return false; return false;
@@ -466,13 +469,14 @@ BMenu::AddItem(BMenu *submenu)
bool bool
BMenu::AddItem(BMenu *submenu, int32 index) BMenu::AddItem(BMenu* submenu, int32 index)
{ {
if (fLayout == B_ITEMS_IN_MATRIX) if (fLayout == B_ITEMS_IN_MATRIX) {
debugger("BMenu::AddItem(BMenuItem *, int32) this method can only " debugger("BMenu::AddItem(BMenuItem*, int32) this method can only "
"be called if the menu layout is not B_ITEMS_IN_MATRIX"); "be called if the menu layout is not B_ITEMS_IN_MATRIX");
}
BMenuItem *item = new (nothrow) BMenuItem(submenu); BMenuItem* item = new (nothrow) BMenuItem(submenu);
if (!item) if (!item)
return false; return false;
@@ -487,13 +491,14 @@ BMenu::AddItem(BMenu *submenu, int32 index)
bool bool
BMenu::AddItem(BMenu *submenu, BRect frame) BMenu::AddItem(BMenu* submenu, BRect frame)
{ {
if (fLayout != B_ITEMS_IN_MATRIX) if (fLayout != B_ITEMS_IN_MATRIX) {
debugger("BMenu::AddItem(BMenu *, BRect) this method can only " debugger("BMenu::AddItem(BMenu*, BRect) this method can only "
"be called if the menu layout is B_ITEMS_IN_MATRIX"); "be called if the menu layout is B_ITEMS_IN_MATRIX");
}
BMenuItem *item = new (nothrow) BMenuItem(submenu); BMenuItem* item = new (nothrow) BMenuItem(submenu);
if (!item) if (!item)
return false; return false;
@@ -508,7 +513,7 @@ BMenu::AddItem(BMenu *submenu, BRect frame)
bool bool
BMenu::AddList(BList *list, int32 index) BMenu::AddList(BList* list, int32 index)
{ {
// TODO: test this function, it's not documented in the bebook. // TODO: test this function, it's not documented in the bebook.
if (list == NULL) if (list == NULL)
@@ -518,7 +523,7 @@ BMenu::AddList(BList *list, int32 index)
int32 numItems = list->CountItems(); int32 numItems = list->CountItems();
for (int32 i = 0; i < numItems; i++) { for (int32 i = 0; i < numItems; i++) {
BMenuItem *item = static_cast<BMenuItem *>(list->ItemAt(i)); BMenuItem* item = static_cast<BMenuItem*>(list->ItemAt(i));
if (item != NULL) { if (item != NULL) {
if (!_AddItem(item, index + i)) if (!_AddItem(item, index + i))
break; break;
@@ -543,7 +548,7 @@ BMenu::AddList(BList *list, int32 index)
bool bool
BMenu::AddSeparatorItem() BMenu::AddSeparatorItem()
{ {
BMenuItem *item = new (nothrow) BSeparatorItem(); BMenuItem* item = new (nothrow) BSeparatorItem();
if (!item || !AddItem(item, CountItems())) { if (!item || !AddItem(item, CountItems())) {
delete item; delete item;
return false; return false;
@@ -554,16 +559,16 @@ BMenu::AddSeparatorItem()
bool bool
BMenu::RemoveItem(BMenuItem *item) BMenu::RemoveItem(BMenuItem* item)
{ {
return _RemoveItems(0, 0, item, false); return _RemoveItems(0, 0, item, false);
} }
BMenuItem * BMenuItem*
BMenu::RemoveItem(int32 index) BMenu::RemoveItem(int32 index)
{ {
BMenuItem *item = ItemAt(index); BMenuItem* item = ItemAt(index);
if (item != NULL) if (item != NULL)
_RemoveItems(0, 0, item, false); _RemoveItems(0, 0, item, false);
return item; return item;
@@ -578,10 +583,10 @@ BMenu::RemoveItems(int32 index, int32 count, bool deleteItems)
bool bool
BMenu::RemoveItem(BMenu *submenu) BMenu::RemoveItem(BMenu* submenu)
{ {
for (int32 i = 0; i < fItems.CountItems(); i++) { for (int32 i = 0; i < fItems.CountItems(); i++) {
if (static_cast<BMenuItem *>(fItems.ItemAtFast(i))->Submenu() == submenu) if (static_cast<BMenuItem*>(fItems.ItemAtFast(i))->Submenu() == submenu)
return _RemoveItems(i, 1, NULL, false); return _RemoveItems(i, 1, NULL, false);
} }
@@ -596,30 +601,30 @@ BMenu::CountItems() const
} }
BMenuItem * BMenuItem*
BMenu::ItemAt(int32 index) const BMenu::ItemAt(int32 index) const
{ {
return static_cast<BMenuItem *>(fItems.ItemAt(index)); return static_cast<BMenuItem*>(fItems.ItemAt(index));
} }
BMenu * BMenu*
BMenu::SubmenuAt(int32 index) const BMenu::SubmenuAt(int32 index) const
{ {
BMenuItem *item = static_cast<BMenuItem *>(fItems.ItemAt(index)); BMenuItem* item = static_cast<BMenuItem*>(fItems.ItemAt(index));
return (item != NULL) ? item->Submenu() : NULL; return item != NULL ? item->Submenu() : NULL;
} }
int32 int32
BMenu::IndexOf(BMenuItem *item) const BMenu::IndexOf(BMenuItem* item) const
{ {
return fItems.IndexOf(item); return fItems.IndexOf(item);
} }
int32 int32
BMenu::IndexOf(BMenu *submenu) const BMenu::IndexOf(BMenu* submenu) const
{ {
for (int32 i = 0; i < fItems.CountItems(); i++) { for (int32 i = 0; i < fItems.CountItems(); i++) {
if (ItemAt(i)->Submenu() == submenu) if (ItemAt(i)->Submenu() == submenu)
@@ -630,10 +635,10 @@ BMenu::IndexOf(BMenu *submenu) const
} }
BMenuItem * BMenuItem*
BMenu::FindItem(const char *label) const BMenu::FindItem(const char* label) const
{ {
BMenuItem *item = NULL; BMenuItem* item = NULL;
for (int32 i = 0; i < CountItems(); i++) { for (int32 i = 0; i < CountItems(); i++) {
item = ItemAt(i); item = ItemAt(i);
@@ -652,10 +657,10 @@ BMenu::FindItem(const char *label) const
} }
BMenuItem * BMenuItem*
BMenu::FindItem(uint32 command) const BMenu::FindItem(uint32 command) const
{ {
BMenuItem *item = NULL; BMenuItem* item = NULL;
for (int32 i = 0; i < CountItems(); i++) { for (int32 i = 0; i < CountItems(); i++) {
item = ItemAt(i); item = ItemAt(i);
@@ -675,7 +680,7 @@ BMenu::FindItem(uint32 command) const
status_t status_t
BMenu::SetTargetForItems(BHandler *handler) BMenu::SetTargetForItems(BHandler* handler)
{ {
status_t status = B_OK; status_t status = B_OK;
for (int32 i = 0; i < fItems.CountItems(); i++) { for (int32 i = 0; i < fItems.CountItems(); i++) {
@@ -792,11 +797,11 @@ BMenu::MaxContentWidth() const
} }
BMenuItem * BMenuItem*
BMenu::FindMarked() BMenu::FindMarked()
{ {
for (int32 i = 0; i < fItems.CountItems(); i++) { for (int32 i = 0; i < fItems.CountItems(); i++) {
BMenuItem *item = ItemAt(i); BMenuItem* item = ItemAt(i);
if (item->IsMarked()) if (item->IsMarked())
return item; return item;
} }
@@ -805,14 +810,14 @@ BMenu::FindMarked()
} }
BMenu * BMenu*
BMenu::Supermenu() const BMenu::Supermenu() const
{ {
return fSuper; return fSuper;
} }
BMenuItem * BMenuItem*
BMenu::Superitem() const BMenu::Superitem() const
{ {
return fSuperitem; return fSuperitem;
@@ -820,7 +825,7 @@ BMenu::Superitem() const
void void
BMenu::MessageReceived(BMessage *msg) BMenu::MessageReceived(BMessage* msg)
{ {
switch (msg->what) { switch (msg->what) {
case B_MOUSE_WHEEL_CHANGED: case B_MOUSE_WHEEL_CHANGED:
@@ -830,7 +835,7 @@ BMenu::MessageReceived(BMessage *msg)
if (deltaY == 0) if (deltaY == 0)
return; return;
BMenuWindow *window = dynamic_cast<BMenuWindow *>(Window()); BMenuWindow* window = dynamic_cast<BMenuWindow*>(Window());
if (window == NULL) if (window == NULL)
return; return;
@@ -847,7 +852,7 @@ BMenu::MessageReceived(BMessage *msg)
void void
BMenu::KeyDown(const char *bytes, int32 numBytes) BMenu::KeyDown(const char* bytes, int32 numBytes)
{ {
// TODO: Test how it works on beos and implement it correctly // TODO: Test how it works on beos and implement it correctly
switch (bytes[0]) { switch (bytes[0]) {
@@ -866,9 +871,9 @@ BMenu::KeyDown(const char *bytes, int32 numBytes)
_SelectNextItem(fSelected, false); _SelectNextItem(fSelected, false);
else { else {
// this case has to be handled a bit specially. // this case has to be handled a bit specially.
BMenuItem *item = Superitem(); BMenuItem* item = Superitem();
if (item) { if (item) {
if (dynamic_cast<BMenuBar *>(Supermenu())) { if (dynamic_cast<BMenuBar*>(Supermenu())) {
// if we're at the top menu below the menu bar, pass the keypress to // if we're at the top menu below the menu bar, pass the keypress to
// the menu bar so we can move to another top level menu // the menu bar so we can move to another top level menu
BMessenger msgr(Supermenu()); BMessenger msgr(Supermenu());
@@ -885,7 +890,7 @@ BMenu::KeyDown(const char *bytes, int32 numBytes)
else { else {
if (fSelected && fSelected->Submenu()) { if (fSelected && fSelected->Submenu()) {
_SelectItem(fSelected, true, true); _SelectItem(fSelected, true, true);
} else if (dynamic_cast<BMenuBar *>(Supermenu())) { } else if (dynamic_cast<BMenuBar*>(Supermenu())) {
// if we have no submenu and we're an // if we have no submenu and we're an
// item in the top menu below the menubar, // item in the top menu below the menubar,
// pass the keypress to the menubar // pass the keypress to the menubar
@@ -899,7 +904,7 @@ BMenu::KeyDown(const char *bytes, int32 numBytes)
case B_PAGE_UP: case B_PAGE_UP:
case B_PAGE_DOWN: case B_PAGE_DOWN:
{ {
BMenuWindow *window = dynamic_cast<BMenuWindow *>(Window()); BMenuWindow* window = dynamic_cast<BMenuWindow*>(Window());
if (window == NULL || !window->HasScrollers()) if (window == NULL || !window->HasScrollers())
break; break;
@@ -988,7 +993,7 @@ BMenu::PreferredSize()
void void
BMenu::GetPreferredSize(float *_width, float *_height) BMenu::GetPreferredSize(float* _width, float* _height)
{ {
_ValidatePreferredSize(); _ValidatePreferredSize();
@@ -1052,12 +1057,12 @@ BMenu::InvalidateLayout(bool descendants)
} }
BHandler * BHandler*
BMenu::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier, BMenu::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier,
int32 form, const char *property) int32 form, const char* property)
{ {
BPropertyInfo propInfo(sPropList); BPropertyInfo propInfo(sPropList);
BHandler *target = NULL; BHandler* target = NULL;
switch (propInfo.FindMatch(msg, 0, specifier, form, property)) { switch (propInfo.FindMatch(msg, 0, specifier, form, property)) {
case B_ERROR: case B_ERROR:
@@ -1098,7 +1103,7 @@ BMenu::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier,
status_t status_t
BMenu::GetSupportedSuites(BMessage *data) BMenu::GetSupportedSuites(BMessage* data)
{ {
if (data == NULL) if (data == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -1195,7 +1200,7 @@ BMenu::AllDetached()
} }
BMenu::BMenu(BRect frame, const char *name, uint32 resizingMode, uint32 flags, BMenu::BMenu(BRect frame, const char* name, uint32 resizingMode, uint32 flags,
menu_layout layout, bool resizeToFit) menu_layout layout, bool resizeToFit)
: BView(frame, name, resizingMode, flags), : BView(frame, name, resizingMode, flags),
fChosenItem(NULL), fChosenItem(NULL),
@@ -1237,8 +1242,8 @@ BMenu::SetItemMargins(float left, float top, float right, float bottom)
void void
BMenu::GetItemMargins(float *left, float *top, float *right, BMenu::GetItemMargins(float* left, float* top, float* right,
float *bottom) const float* bottom) const
{ {
if (left != NULL) if (left != NULL)
*left = fPad.left; *left = fPad.left;
@@ -1281,8 +1286,8 @@ BMenu::Hide()
} }
BMenuItem * BMenuItem*
BMenu::Track(bool sticky, BRect *clickToOpenRect) BMenu::Track(bool sticky, BRect* clickToOpenRect)
{ {
if (sticky && LockLooper()) { if (sticky && LockLooper()) {
//RedrawAfterSticky(Bounds()); //RedrawAfterSticky(Bounds());
@@ -1299,7 +1304,7 @@ BMenu::Track(bool sticky, BRect *clickToOpenRect)
_SetStickyMode(sticky); _SetStickyMode(sticky);
int action; int action;
BMenuItem *menuItem = _Track(&action); BMenuItem* menuItem = _Track(&action);
fExtraRect = NULL; fExtraRect = NULL;
@@ -1351,7 +1356,7 @@ BMenu::DrawBackground(BRect update)
void void
BMenu::SetTrackingHook(menu_tracking_hook func, void *state) BMenu::SetTrackingHook(menu_tracking_hook func, void* state)
{ {
delete fExtraMenuData; delete fExtraMenuData;
fExtraMenuData = new (nothrow) BPrivate::ExtraMenuData(func, state); fExtraMenuData = new (nothrow) BPrivate::ExtraMenuData(func, state);
@@ -1364,13 +1369,6 @@ void BMenu::_ReservedMenu5() {}
void BMenu::_ReservedMenu6() {} void BMenu::_ReservedMenu6() {}
BMenu &
BMenu::operator=(const BMenu &)
{
return *this;
}
void void
BMenu::_InitData(BMessage* archive) BMenu::_InitData(BMessage* archive)
{ {
@@ -1389,7 +1387,7 @@ BMenu::_InitData(BMessage* archive)
fTriggerEnabled = sMenuInfo.triggers_always_shown; fTriggerEnabled = sMenuInfo.triggers_always_shown;
if (archive != NULL) { if (archive != NULL) {
archive->FindInt32("_layout", (int32 *)&fLayout); archive->FindInt32("_layout", (int32*)&fLayout);
archive->FindBool("_rsize_to_fit", &fResizeToFit); archive->FindBool("_rsize_to_fit", &fResizeToFit);
bool disabled; bool disabled;
if (archive->FindBool("_disable", &disabled) == B_OK) if (archive->FindBool("_disable", &disabled) == B_OK)
@@ -1405,8 +1403,8 @@ BMenu::_InitData(BMessage* archive)
BMessage msg; BMessage msg;
for (int32 i = 0; archive->FindMessage("_items", i, &msg) == B_OK; i++) { for (int32 i = 0; archive->FindMessage("_items", i, &msg) == B_OK; i++) {
BArchivable *object = instantiate_object(&msg); BArchivable* object = instantiate_object(&msg);
if (BMenuItem *item = dynamic_cast<BMenuItem *>(object)) { if (BMenuItem* item = dynamic_cast<BMenuItem*>(object)) {
BRect bounds; BRect bounds;
if (fLayout == B_ITEMS_IN_MATRIX if (fLayout == B_ITEMS_IN_MATRIX
&& archive->FindRect("_i_frames", i, &bounds) == B_OK) && archive->FindRect("_i_frames", i, &bounds) == B_OK)
@@ -1424,7 +1422,7 @@ BMenu::_Show(bool selectFirstItem)
{ {
// See if the supermenu has a cached menuwindow, // See if the supermenu has a cached menuwindow,
// and use that one if possible. // and use that one if possible.
BMenuWindow *window = NULL; BMenuWindow* window = NULL;
bool ourWindow = false; bool ourWindow = false;
if (fSuper != NULL) { if (fSuper != NULL) {
fSuperbounds = fSuper->ConvertToScreen(fSuper->Bounds()); fSuperbounds = fSuper->ConvertToScreen(fSuper->Bounds());
@@ -1481,7 +1479,7 @@ BMenu::_Show(bool selectFirstItem)
void void
BMenu::_Hide() BMenu::_Hide()
{ {
BMenuWindow *window = dynamic_cast<BMenuWindow *>(Window()); BMenuWindow* window = dynamic_cast<BMenuWindow*>(Window());
if (window == NULL || !window->Lock()) if (window == NULL || !window->Lock())
return; return;
@@ -1513,11 +1511,11 @@ const static int32 kMouseMotionThreshold = 15;
// TODO: Same as above. Actually, we could get rid of the kHysteresis // TODO: Same as above. Actually, we could get rid of the kHysteresis
BMenuItem * BMenuItem*
BMenu::_Track(int *action, long start) BMenu::_Track(int* action, long start)
{ {
// TODO: cleanup // TODO: cleanup
BMenuItem *item = NULL; BMenuItem* item = NULL;
BRect navAreaRectAbove, navAreaRectBelow; BRect navAreaRectAbove, navAreaRectBelow;
bigtime_t selectedTime = system_time(); bigtime_t selectedTime = system_time();
bigtime_t navigationAreaTime = 0; bigtime_t navigationAreaTime = 0;
@@ -1543,7 +1541,7 @@ BMenu::_Track(int *action, long start)
if (!LockLooper()) if (!LockLooper())
break; break;
BMenuWindow *window = static_cast<BMenuWindow *>(Window()); BMenuWindow* window = static_cast<BMenuWindow*>(Window());
BPoint screenLocation = ConvertToScreen(location); BPoint screenLocation = ConvertToScreen(location);
if (window->CheckForScrolling(screenLocation)) { if (window->CheckForScrolling(screenLocation)) {
UnlockLooper(); UnlockLooper();
@@ -1567,14 +1565,14 @@ BMenu::_Track(int *action, long start)
// redraw itself // redraw itself
UnlockLooper(); UnlockLooper();
int submenuAction = MENU_STATE_TRACKING; int submenuAction = MENU_STATE_TRACKING;
BMenu *submenu = fSelected->Submenu(); BMenu* submenu = fSelected->Submenu();
submenu->_SetStickyMode(_IsStickyMode()); submenu->_SetStickyMode(_IsStickyMode());
// The following call blocks until the submenu // The following call blocks until the submenu
// gives control back to us, either because the mouse // gives control back to us, either because the mouse
// pointer goes out of the submenu's bounds, or because // pointer goes out of the submenu's bounds, or because
// the user closes the menu // the user closes the menu
BMenuItem *submenuItem = submenu->_Track(&submenuAction); BMenuItem* submenuItem = submenu->_Track(&submenuAction);
if (submenuAction == MENU_STATE_CLOSED) { if (submenuAction == MENU_STATE_CLOSED) {
item = submenuItem; item = submenuItem;
fState = MENU_STATE_CLOSED; fState = MENU_STATE_CLOSED;
@@ -1627,7 +1625,8 @@ BMenu::_Track(int *action, long start)
// mouseSpeed in px per ms // mouseSpeed in px per ms
// (actually point_distance returns the square of the distance, // (actually point_distance returns the square of the distance,
// so it's more px^2 per ms) // so it's more px^2 per ms)
mouseSpeed = (int32)(point_distance(newLocation, location) * 1000 / (newPollTime - pollTime)); mouseSpeed = (int32)(point_distance(newLocation, location) * 1000
/ (newPollTime - pollTime));
pollTime = newPollTime; pollTime = newPollTime;
if (newLocation != location || newButtons != buttons) { if (newLocation != location || newButtons != buttons) {
@@ -1698,7 +1697,7 @@ BMenu::_UpdateNavigationArea(BPoint position, BRect& navAreaRectAbove,
if (fSelected == NULL) if (fSelected == NULL)
return; return;
BMenu *submenu = fSelected->Submenu(); BMenu* submenu = fSelected->Submenu();
if (submenu != NULL) { if (submenu != NULL) {
BRect menuBounds = ConvertToScreen(Bounds()); BRect menuBounds = ConvertToScreen(Bounds());
@@ -1857,7 +1856,7 @@ BMenu::_UpdateStateClose(BMenuItem* item, const BPoint& where,
bool bool
BMenu::_AddItem(BMenuItem *item, int32 index) BMenu::_AddItem(BMenuItem* item, int32 index)
{ {
ASSERT(item != NULL); ASSERT(item != NULL);
if (index < 0 || index > fItems.CountItems()) if (index < 0 || index > fItems.CountItems())
@@ -1885,13 +1884,13 @@ BMenu::_AddItem(BMenuItem *item, int32 index)
bool bool
BMenu::_RemoveItems(int32 index, int32 count, BMenuItem *item, bool deleteItems) BMenu::_RemoveItems(int32 index, int32 count, BMenuItem* item, bool deleteItems)
{ {
bool success = false; bool success = false;
bool invalidateLayout = false; bool invalidateLayout = false;
bool locked = LockLooper(); bool locked = LockLooper();
BWindow *window = Window(); BWindow* window = Window();
// The plan is simple: If we're given a BMenuItem directly, we use it // The plan is simple: If we're given a BMenuItem directly, we use it
// and ignore index and count. Otherwise, we use them instead. // and ignore index and count. Otherwise, we use them instead.
@@ -2060,7 +2059,7 @@ BMenu::_ComputeColumnLayout(int32 index, bool bestFit, bool moveItems,
frame.Set(0, 0, 0, -1); frame.Set(0, 0, 0, -1);
for (; index < fItems.CountItems(); index++) { for (; index < fItems.CountItems(); index++) {
BMenuItem *item = ItemAt(index); BMenuItem* item = ItemAt(index);
float width, height; float width, height;
item->GetContentSize(&width, &height); item->GetContentSize(&width, &height);
@@ -2121,7 +2120,7 @@ BMenu::_ComputeRowLayout(int32 index, bool bestFit, bool moveItems,
+ fPad.bottom)); + fPad.bottom));
for (int32 i = 0; i < fItems.CountItems(); i++) { for (int32 i = 0; i < fItems.CountItems(); i++) {
BMenuItem *item = ItemAt(i); BMenuItem* item = ItemAt(i);
float width, height; float width, height;
item->GetContentSize(&width, &height); item->GetContentSize(&width, &height);
@@ -2152,7 +2151,7 @@ BMenu::_ComputeMatrixLayout(BRect &frame)
{ {
frame.Set(0, 0, 0, 0); frame.Set(0, 0, 0, 0);
for (int32 i = 0; i < CountItems(); i++) { for (int32 i = 0; i < CountItems(); i++) {
BMenuItem *item = ItemAt(i); BMenuItem* item = ItemAt(i);
if (item != NULL) { if (item != NULL) {
frame.left = min_c(frame.left, item->Frame().left); frame.left = min_c(frame.left, item->Frame().left);
frame.right = max_c(frame.right, item->Frame().right); frame.right = max_c(frame.right, item->Frame().right);
@@ -2167,8 +2166,8 @@ BMenu::_ComputeMatrixLayout(BRect &frame)
BPoint BPoint
BMenu::ScreenLocation() BMenu::ScreenLocation()
{ {
BMenu *superMenu = Supermenu(); BMenu* superMenu = Supermenu();
BMenuItem *superItem = Superitem(); BMenuItem* superItem = Superitem();
if (superMenu == NULL || superItem == NULL) { if (superMenu == NULL || superItem == NULL) {
debugger("BMenu can't determine where to draw." debugger("BMenu can't determine where to draw."
@@ -2188,7 +2187,7 @@ BMenu::ScreenLocation()
BRect BRect
BMenu::_CalcFrame(BPoint where, bool *scrollOn) BMenu::_CalcFrame(BPoint where, bool* scrollOn)
{ {
// TODO: Improve me // TODO: Improve me
BRect bounds = Bounds(); BRect bounds = Bounds();
@@ -2197,15 +2196,15 @@ BMenu::_CalcFrame(BPoint where, bool *scrollOn)
BScreen screen(Window()); BScreen screen(Window());
BRect screenFrame = screen.Frame(); BRect screenFrame = screen.Frame();
BMenu *superMenu = Supermenu(); BMenu* superMenu = Supermenu();
BMenuItem *superItem = Superitem(); BMenuItem* superItem = Superitem();
bool scroll = false; bool scroll = false;
// TODO: Horrible hack: // TODO: Horrible hack:
// When added to a BMenuField, a BPopUpMenu is the child of // When added to a BMenuField, a BPopUpMenu is the child of
// a _BMCMenuBar_ to "fake" the menu hierarchy // a _BMCMenuBar_ to "fake" the menu hierarchy
if (superMenu == NULL || superItem == NULL if (superMenu == NULL || superItem == NULL
|| dynamic_cast<_BMCMenuBar_ *>(superMenu) != NULL) { || dynamic_cast<_BMCMenuBar_*>(superMenu) != NULL) {
// just move the window on screen // just move the window on screen
if (frame.bottom > screenFrame.bottom) if (frame.bottom > screenFrame.bottom)
@@ -2217,7 +2216,6 @@ BMenu::_CalcFrame(BPoint where, bool *scrollOn)
frame.OffsetBy(screenFrame.right - frame.right, 0); frame.OffsetBy(screenFrame.right - frame.right, 0);
else if (frame.left < screenFrame.left) else if (frame.left < screenFrame.left)
frame.OffsetBy(-frame.left, 0); frame.OffsetBy(-frame.left, 0);
} else if (superMenu->Layout() == B_ITEMS_IN_COLUMN) { } else if (superMenu->Layout() == B_ITEMS_IN_COLUMN) {
if (frame.right > screenFrame.right) if (frame.right > screenFrame.right)
frame.OffsetBy(-superItem->Frame().Width() - frame.Width() - 2, 0); frame.OffsetBy(-superItem->Frame().Width() - frame.Width() - 2, 0);
@@ -2230,7 +2228,7 @@ BMenu::_CalcFrame(BPoint where, bool *scrollOn)
} else { } else {
if (frame.bottom > screenFrame.bottom) { if (frame.bottom > screenFrame.bottom) {
if (scrollOn != NULL && superMenu != NULL if (scrollOn != NULL && superMenu != NULL
&& dynamic_cast<BMenuBar *>(superMenu) != NULL && dynamic_cast<BMenuBar*>(superMenu) != NULL
&& frame.top < (screenFrame.bottom - 80)) { && frame.top < (screenFrame.bottom - 80)) {
scroll = true; scroll = true;
} else { } else {
@@ -2262,7 +2260,7 @@ BMenu::_DrawItems(BRect updateRect)
{ {
int32 itemCount = fItems.CountItems(); int32 itemCount = fItems.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->Frame().Intersects(updateRect)) if (item->Frame().Intersects(updateRect))
item->Draw(); item->Draw();
} }
@@ -2270,7 +2268,7 @@ BMenu::_DrawItems(BRect updateRect)
int int
BMenu::_State(BMenuItem **item) const BMenu::_State(BMenuItem** item) const
{ {
if (fState == MENU_STATE_TRACKING || fState == MENU_STATE_CLOSED) if (fState == MENU_STATE_TRACKING || fState == MENU_STATE_CLOSED)
return fState; return fState;
@@ -2283,7 +2281,7 @@ BMenu::_State(BMenuItem **item) const
void void
BMenu::_InvokeItem(BMenuItem *item, bool now) BMenu::_InvokeItem(BMenuItem* item, bool now)
{ {
if (!item->IsEnabled()) if (!item->IsEnabled())
return; return;
@@ -2308,8 +2306,8 @@ BMenu::_InvokeItem(BMenuItem *item, bool now)
} }
// Lock the root menu window before calling BMenuItem::Invoke() // Lock the root menu window before calling BMenuItem::Invoke()
BMenu *parent = this; BMenu* parent = this;
BMenu *rootMenu = NULL; BMenu* rootMenu = NULL;
do { do {
rootMenu = parent; rootMenu = parent;
parent = rootMenu->Supermenu(); parent = rootMenu->Supermenu();
@@ -2333,12 +2331,12 @@ BMenu::_OverSuper(BPoint location)
bool bool
BMenu::_OverSubmenu(BMenuItem *item, BPoint loc) BMenu::_OverSubmenu(BMenuItem* item, BPoint loc)
{ {
if (item == NULL) if (item == NULL)
return false; return false;
BMenu *subMenu = item->Submenu(); BMenu* subMenu = item->Submenu();
if (subMenu == NULL || subMenu->Window() == NULL) if (subMenu == NULL || subMenu->Window() == NULL)
return false; return false;
@@ -2350,7 +2348,7 @@ BMenu::_OverSubmenu(BMenuItem *item, BPoint loc)
} }
BMenuWindow * BMenuWindow*
BMenu::_MenuWindow() BMenu::_MenuWindow()
{ {
#if USE_CACHED_MENUWINDOW #if USE_CACHED_MENUWINDOW
@@ -2375,7 +2373,7 @@ BMenu::_DeleteMenuWindow()
} }
BMenuItem * BMenuItem*
BMenu::_HitTestItems(BPoint where, BPoint slop) const BMenu::_HitTestItems(BPoint where, BPoint slop) const
{ {
// TODO: Take "slop" into account ? // TODO: Take "slop" into account ?
@@ -2387,7 +2385,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->Frame().Contains(where)) if (item->Frame().Contains(where))
return item; return item;
} }
@@ -2415,7 +2413,7 @@ BMenu::_CacheFontInfo()
void void
BMenu::_ItemMarked(BMenuItem *item) BMenu::_ItemMarked(BMenuItem* item)
{ {
if (IsRadioMode()) { if (IsRadioMode()) {
for (int32 i = 0; i < CountItems(); i++) { for (int32 i = 0; i < CountItems(); i++) {
@@ -2431,7 +2429,7 @@ BMenu::_ItemMarked(BMenuItem *item)
void void
BMenu::_Install(BWindow *target) BMenu::_Install(BWindow* target)
{ {
for (int32 i = 0; i < CountItems(); i++) for (int32 i = 0; i < CountItems(); i++)
ItemAt(i)->Install(target); ItemAt(i)->Install(target);
@@ -2454,7 +2452,7 @@ BMenu::_SelectItem(BMenuItem* menuItem, bool showSubmenu, bool selectFirstItem)
if (menuItem != fSelected) { if (menuItem != fSelected) {
if (fSelected != NULL) { if (fSelected != NULL) {
fSelected->Select(false); fSelected->Select(false);
BMenu *subMenu = fSelected->Submenu(); BMenu* subMenu = fSelected->Submenu();
if (subMenu != NULL && subMenu->Window() != NULL) if (subMenu != NULL && subMenu->Window() != NULL)
subMenu->_Hide(); subMenu->_Hide();
} }
@@ -2465,7 +2463,7 @@ BMenu::_SelectItem(BMenuItem* menuItem, bool showSubmenu, bool selectFirstItem)
} }
if (fSelected != NULL && showSubmenu) { if (fSelected != NULL && showSubmenu) {
BMenu *subMenu = fSelected->Submenu(); BMenu* subMenu = fSelected->Submenu();
if (subMenu != NULL && subMenu->Window() == NULL) { if (subMenu != NULL && subMenu->Window() == NULL) {
if (!subMenu->_Show(selectFirstItem)) { if (!subMenu->_Show(selectFirstItem)) {
// something went wrong, deselect the item // something went wrong, deselect the item
@@ -2478,25 +2476,25 @@ BMenu::_SelectItem(BMenuItem* menuItem, bool showSubmenu, bool selectFirstItem)
bool bool
BMenu::_SelectNextItem(BMenuItem *item, bool forward) BMenu::_SelectNextItem(BMenuItem* item, bool forward)
{ {
if (CountItems() == 0) // cannot select next item in an empty menu if (CountItems() == 0) // cannot select next item in an empty menu
return false; return false;
BMenuItem *nextItem = _NextItem(item, forward); BMenuItem* nextItem = _NextItem(item, forward);
if (nextItem == NULL) if (nextItem == NULL)
return false; return false;
bool openMenu = false; bool openMenu = false;
if (dynamic_cast<BMenuBar *>(this) != NULL) if (dynamic_cast<BMenuBar*>(this) != NULL)
openMenu = true; openMenu = true;
_SelectItem(nextItem, openMenu); _SelectItem(nextItem, openMenu);
return true; return true;
} }
BMenuItem * BMenuItem*
BMenu::_NextItem(BMenuItem *item, bool forward) const BMenu::_NextItem(BMenuItem* item, bool forward) const
{ {
// go to next item, and skip over disabled items such as separators // go to next item, and skip over disabled items such as separators
int32 index = fItems.IndexOf(item); int32 index = fItems.IndexOf(item);
@@ -2549,7 +2547,7 @@ BMenu::_SetStickyMode(bool on)
fSuper->_SetStickyMode(on); fSuper->_SetStickyMode(on);
else { else {
// TODO: Ugly hack, but it needs to be done right here in this method // TODO: Ugly hack, but it needs to be done right here in this method
BMenuBar *menuBar = dynamic_cast<BMenuBar *>(this); BMenuBar* menuBar = dynamic_cast<BMenuBar*>(this);
if (on && menuBar != NULL && menuBar->LockLooper()) { if (on && menuBar != NULL && menuBar->LockLooper()) {
// Steal the focus from the current focus view // Steal the focus from the current focus view
// (needed to handle keyboard navigation) // (needed to handle keyboard navigation)
@@ -2581,7 +2579,7 @@ BMenu::_CalcTriggers()
// Set triggers for items which don't have one yet // Set triggers for items which don't have one yet
for (int32 i = 0; i < CountItems(); i++) { for (int32 i = 0; i < CountItems(); i++) {
BMenuItem *item = ItemAt(i); BMenuItem* item = ItemAt(i);
if (item->Trigger() == 0) { if (item->Trigger() == 0) {
uint32 trigger; uint32 trigger;
int32 index; int32 index;
@@ -2593,7 +2591,7 @@ BMenu::_CalcTriggers()
bool bool
BMenu::_ChooseTrigger(const char *title, int32& index, uint32& trigger, BMenu::_ChooseTrigger(const char* title, int32& index, uint32& trigger,
BPrivate::TriggerList& triggers) BPrivate::TriggerList& triggers)
{ {
if (title == NULL) if (title == NULL)
@@ -2629,19 +2627,19 @@ BMenu::_ChooseTrigger(const char *title, int32& index, uint32& trigger,
void void
BMenu::_UpdateWindowViewSize(bool updatePosition) BMenu::_UpdateWindowViewSize(bool updatePosition)
{ {
BMenuWindow *window = static_cast<BMenuWindow *>(Window()); BMenuWindow* window = static_cast<BMenuWindow*>(Window());
if (window == NULL) if (window == NULL)
return; return;
if (dynamic_cast<BMenuBar *>(this) != NULL) if (dynamic_cast<BMenuBar*>(this) != NULL)
return; return;
if (!fResizeToFit) if (!fResizeToFit)
return; return;
bool scroll = false; bool scroll = false;
const BPoint screenLocation = updatePosition ? ScreenLocation() const BPoint screenLocation = updatePosition
: window->Frame().LeftTop(); ? ScreenLocation() : window->Frame().LeftTop();
BRect frame = _CalcFrame(screenLocation, &scroll); BRect frame = _CalcFrame(screenLocation, &scroll);
ResizeTo(frame.Width(), frame.Height()); ResizeTo(frame.Width(), frame.Height());
@@ -2653,7 +2651,7 @@ BMenu::_UpdateWindowViewSize(bool updatePosition)
// If we need scrolling, resize the window to fit the screen and // If we need scrolling, resize the window to fit the screen and
// attach scrollers to our cached BMenuWindow. // attach scrollers to our cached BMenuWindow.
if (dynamic_cast<BMenuBar *>(Supermenu()) == NULL) { if (dynamic_cast<BMenuBar*>(Supermenu()) == NULL) {
window->ResizeTo(Bounds().Width(), screen.Frame().bottom); window->ResizeTo(Bounds().Width(), screen.Frame().bottom);
frame.top = 0; frame.top = 0;
} else { } else {
@@ -2690,7 +2688,7 @@ BMenu::_OkToProceed(BMenuItem* item)
// TODO: I added the check for BMenuBar to solve a problem with Deskbar. // TODO: I added the check for BMenuBar to solve a problem with Deskbar.
// BeOS seems to do something similar. This could also be a bug in Deskbar, though. // BeOS seems to do something similar. This could also be a bug in Deskbar, though.
if ((buttons != 0 && stickyMode) if ((buttons != 0 && stickyMode)
|| ((dynamic_cast<BMenuBar *>(this) == NULL || ((dynamic_cast<BMenuBar*>(this) == NULL
&& (buttons == 0 && !stickyMode)) || _HitTestItems(where) != item)) && (buttons == 0 && !stickyMode)) || _HitTestItems(where) != item))
return false; return false;
@@ -2714,7 +2712,7 @@ void
BMenu::_QuitTracking(bool onlyThis) BMenu::_QuitTracking(bool onlyThis)
{ {
_SelectItem(NULL); _SelectItem(NULL);
if (BMenuBar *menuBar = dynamic_cast<BMenuBar *>(this)) if (BMenuBar* menuBar = dynamic_cast<BMenuBar*>(this))
menuBar->_RestoreFocus(); menuBar->_RestoreFocus();
fChosenItem = NULL; fChosenItem = NULL;
@@ -2732,9 +2730,10 @@ BMenu::_QuitTracking(bool onlyThis)
// TODO: Maybe the following two methods would fit better into InterfaceDefs.cpp // TODO: Maybe the following two methods would fit better into InterfaceDefs.cpp
// In R5, they do all the work client side, we let the app_server handle the details. // In R5, they do all the work client side, we let the app_server handle the
// details.
status_t status_t
set_menu_info(menu_info *info) set_menu_info(menu_info* info)
{ {
if (!info) if (!info)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -2753,7 +2752,7 @@ set_menu_info(menu_info *info)
status_t status_t
get_menu_info(menu_info *info) get_menu_info(menu_info* info)
{ {
if (!info) if (!info)
return B_BAD_VALUE; return B_BAD_VALUE;
+52 -43
View File
@@ -8,6 +8,7 @@
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
*/ */
#include <MenuBar.h> #include <MenuBar.h>
#include <math.h> #include <math.h>
@@ -31,20 +32,21 @@ using BPrivate::gDefaultTokens;
struct menubar_data { struct menubar_data {
BMenuBar *menuBar; BMenuBar* menuBar;
int32 menuIndex; int32 menuIndex;
bool sticky; bool sticky;
bool showMenu; bool showMenu;
bool useRect; bool useRect;
BRect rect; BRect rect;
}; };
BMenuBar::BMenuBar(BRect frame, const char *title, uint32 resizeMask, BMenuBar::BMenuBar(BRect frame, const char* title, uint32 resizeMask,
menu_layout layout, bool resizeToFit) menu_layout layout, bool resizeToFit)
: BMenu(frame, title, resizeMask, B_WILL_DRAW | B_FRAME_EVENTS, layout, :
BMenu(frame, title, resizeMask, B_WILL_DRAW | B_FRAME_EVENTS, layout,
resizeToFit), resizeToFit),
fBorder(B_BORDER_FRAME), fBorder(B_BORDER_FRAME),
fTrackingPID(-1), fTrackingPID(-1),
@@ -57,8 +59,9 @@ BMenuBar::BMenuBar(BRect frame, const char *title, uint32 resizeMask,
} }
BMenuBar::BMenuBar(const char *title, menu_layout layout, uint32 flags) BMenuBar::BMenuBar(const char* title, menu_layout layout, uint32 flags)
: BMenu(BRect(), title, B_FOLLOW_NONE, :
BMenu(BRect(), title, B_FOLLOW_NONE,
flags | B_WILL_DRAW | B_FRAME_EVENTS | B_SUPPORTS_LAYOUT, flags | B_WILL_DRAW | B_FRAME_EVENTS | B_SUPPORTS_LAYOUT,
layout, false), layout, false),
fBorder(B_BORDER_FRAME), fBorder(B_BORDER_FRAME),
@@ -72,8 +75,9 @@ BMenuBar::BMenuBar(const char *title, menu_layout layout, uint32 flags)
} }
BMenuBar::BMenuBar(BMessage *data) BMenuBar::BMenuBar(BMessage* data)
: BMenu(data), :
BMenu(data),
fBorder(B_BORDER_FRAME), fBorder(B_BORDER_FRAME),
fTrackingPID(-1), fTrackingPID(-1),
fPrevFocusToken(-1), fPrevFocusToken(-1),
@@ -87,7 +91,7 @@ BMenuBar::BMenuBar(BMessage *data)
SetBorder((menu_bar_border)border); SetBorder((menu_bar_border)border);
menu_layout layout = B_ITEMS_IN_COLUMN; menu_layout layout = B_ITEMS_IN_COLUMN;
data->FindInt32("_layout", (int32 *)&layout); data->FindInt32("_layout", (int32*)&layout);
_InitData(layout); _InitData(layout);
} }
@@ -104,8 +108,8 @@ BMenuBar::~BMenuBar()
} }
BArchivable * BArchivable*
BMenuBar::Instantiate(BMessage *data) BMenuBar::Instantiate(BMessage* data)
{ {
if (validate_instantiation(data, "BMenuBar")) if (validate_instantiation(data, "BMenuBar"))
return new BMenuBar(data); return new BMenuBar(data);
@@ -115,7 +119,7 @@ BMenuBar::Instantiate(BMessage *data)
status_t status_t
BMenuBar::Archive(BMessage *data, bool deep) const BMenuBar::Archive(BMessage* data, bool deep) const
{ {
status_t err = BMenu::Archive(data, deep); status_t err = BMenu::Archive(data, deep);
@@ -183,7 +187,8 @@ BMenuBar::Draw(BRect updateRect)
BPoint(bounds.right, bounds.bottom - 1.0f)); BPoint(bounds.right, bounds.bottom - 1.0f));
SetHighColor(tint_color(noTint, B_DARKEN_2_TINT)); SetHighColor(tint_color(noTint, B_DARKEN_2_TINT));
StrokeLine(BPoint(0.0f, bounds.bottom), BPoint(bounds.right, bounds.bottom)); StrokeLine(BPoint(0.0f, bounds.bottom),
BPoint(bounds.right, bounds.bottom));
StrokeLine(BPoint(bounds.right, 0.0f), BPoint(bounds.right, bounds.bottom)); StrokeLine(BPoint(bounds.right, 0.0f), BPoint(bounds.right, bounds.bottom));
SetHighColor(color); SetHighColor(color);
@@ -213,7 +218,7 @@ BMenuBar::DetachedFromWindow()
void void
BMenuBar::MessageReceived(BMessage *msg) BMenuBar::MessageReceived(BMessage* msg)
{ {
BMenu::MessageReceived(msg); BMenu::MessageReceived(msg);
} }
@@ -225,7 +230,7 @@ BMenuBar::MouseDown(BPoint where)
if (fTracking) if (fTracking)
return; return;
BWindow *window = Window(); BWindow* window = Window();
if (!window->IsActive() || !window->IsFront()) { if (!window->IsActive() || !window->IsFront()) {
window->Activate(); window->Activate();
window->UpdateIfNeeded(); window->UpdateIfNeeded();
@@ -293,15 +298,16 @@ BMenuBar::Hide()
} }
BHandler * BHandler*
BMenuBar::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier, int32 form, const char *property) BMenuBar::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier,
int32 form, const char* property)
{ {
return BMenu::ResolveSpecifier(msg, index, specifier, form, property); return BMenu::ResolveSpecifier(msg, index, specifier, form, property);
} }
status_t status_t
BMenuBar::GetSupportedSuites(BMessage *data) BMenuBar::GetSupportedSuites(BMessage* data)
{ {
return BMenu::GetSupportedSuites(data); return BMenu::GetSupportedSuites(data);
} }
@@ -315,7 +321,7 @@ BMenuBar::ResizeToPreferred()
void void
BMenuBar::GetPreferredSize(float *width, float *height) BMenuBar::GetPreferredSize(float* width, float* height)
{ {
BMenu::GetPreferredSize(width, height); BMenu::GetPreferredSize(width, height);
} }
@@ -373,7 +379,7 @@ BMenuBar::Perform(perform_code code, void* _data)
BMenuBar::GetHeightForWidth(data->width, &data->min, &data->max, BMenuBar::GetHeightForWidth(data->width, &data->min, &data->max,
&data->preferred); &data->preferred);
return B_OK; return B_OK;
} }
case PERFORM_CODE_SET_LAYOUT: case PERFORM_CODE_SET_LAYOUT:
{ {
perform_data_set_layout* data = (perform_data_set_layout*)_data; perform_data_set_layout* data = (perform_data_set_layout*)_data;
@@ -438,12 +444,13 @@ BMenuBar::operator=(const BMenuBar &)
void void
BMenuBar::StartMenuBar(int32 menuIndex, bool sticky, bool showMenu, BRect *specialRect) BMenuBar::StartMenuBar(int32 menuIndex, bool sticky, bool showMenu,
BRect* specialRect)
{ {
if (fTracking) if (fTracking)
return; return;
BWindow *window = Window(); BWindow* window = Window();
if (window == NULL) if (window == NULL)
debugger("MenuBar must be added to a window before it can be used."); debugger("MenuBar must be added to a window before it can be used.");
@@ -461,7 +468,8 @@ BMenuBar::StartMenuBar(int32 menuIndex, bool sticky, bool showMenu, BRect *speci
fMenuSem = create_sem(0, "window close sem"); fMenuSem = create_sem(0, "window close sem");
_set_menu_sem_(window, fMenuSem); _set_menu_sem_(window, fMenuSem);
fTrackingPID = spawn_thread(_TrackTask, "menu_tracking", B_DISPLAY_PRIORITY, NULL); fTrackingPID = spawn_thread(_TrackTask, "menu_tracking", B_DISPLAY_PRIORITY,
NULL);
if (fTrackingPID >= 0) { if (fTrackingPID >= 0) {
menubar_data data; menubar_data data;
data.menuBar = this; data.menuBar = this;
@@ -482,15 +490,14 @@ BMenuBar::StartMenuBar(int32 menuIndex, bool sticky, bool showMenu, BRect *speci
} }
/* static */ /*static*/ int32
int32 BMenuBar::_TrackTask(void* arg)
BMenuBar::_TrackTask(void *arg)
{ {
menubar_data data; menubar_data data;
thread_id id; thread_id id;
receive_data(&id, &data, sizeof(data)); receive_data(&id, &data, sizeof(data));
BMenuBar *menuBar = data.menuBar; BMenuBar* menuBar = data.menuBar;
if (data.useRect) if (data.useRect)
menuBar->fExtraRect = &data.rect; menuBar->fExtraRect = &data.rect;
menuBar->_SetStickyMode(data.sticky); menuBar->_SetStickyMode(data.sticky);
@@ -502,7 +509,7 @@ BMenuBar::_TrackTask(void *arg)
menuBar->fExtraRect = NULL; menuBar->fExtraRect = NULL;
// We aren't the BWindow thread, so don't call MenusEnded() directly // We aren't the BWindow thread, so don't call MenusEnded() directly
BWindow *window = menuBar->Window(); BWindow* window = menuBar->Window();
window->PostMessage(_MENUS_DONE_); window->PostMessage(_MENUS_DONE_);
_set_menu_sem_(window, B_BAD_SEM_ID); _set_menu_sem_(window, B_BAD_SEM_ID);
@@ -513,13 +520,13 @@ BMenuBar::_TrackTask(void *arg)
} }
BMenuItem * BMenuItem*
BMenuBar::_Track(int32 *action, int32 startIndex, bool showMenu) BMenuBar::_Track(int32* action, int32 startIndex, bool showMenu)
{ {
// TODO: Cleanup, merge some "if" blocks if possible // TODO: Cleanup, merge some "if" blocks if possible
fChosenItem = NULL; fChosenItem = NULL;
BWindow *window = Window(); BWindow* window = Window();
fState = MENU_STATE_TRACKING; fState = MENU_STATE_TRACKING;
BPoint where; BPoint where;
@@ -546,7 +553,7 @@ BMenuBar::_Track(int32 *action, int32 startIndex, bool showMenu)
if (_OverSubmenu(fSelected, ConvertToScreen(where))) { if (_OverSubmenu(fSelected, ConvertToScreen(where))) {
// call _Track() from the selected sub-menu when the mouse cursor // call _Track() from the selected sub-menu when the mouse cursor
// is over its window // is over its window
BMenu *menu = fSelected->Submenu(); BMenu* menu = fSelected->Submenu();
window->Unlock(); window->Unlock();
snoozeAmount = 30000; snoozeAmount = 30000;
bool wasSticky = _IsStickyMode(); bool wasSticky = _IsStickyMode();
@@ -571,7 +578,8 @@ BMenuBar::_Track(int32 *action, int32 startIndex, bool showMenu)
// that are children of BMenuFields "sticky" (see ticket #953) // that are children of BMenuFields "sticky" (see ticket #953)
if (localAction == MENU_STATE_CLOSED) { if (localAction == MENU_STATE_CLOSED) {
if (fExtraRect != NULL && fExtraRect->Contains(where) if (fExtraRect != NULL && fExtraRect->Contains(where)
// 9 = 3 pixels ^ 2 (since point_distance() returns the square of the distance) // 9 = 3 pixels ^ 2 (since point_distance() returns the
// square of the distance)
&& point_distance(newWhere, where) < 9) { && point_distance(newWhere, where) < 9) {
_SetStickyMode(true); _SetStickyMode(true);
fExtraRect = NULL; fExtraRect = NULL;
@@ -669,9 +677,9 @@ BMenuBar::_StealFocus()
if (fPrevFocusToken != -1) if (fPrevFocusToken != -1)
return; return;
BWindow *window = Window(); BWindow* window = Window();
if (window != NULL && window->Lock()) { if (window != NULL && window->Lock()) {
BView *focus = window->CurrentFocus(); BView* focus = window->CurrentFocus();
if (focus != NULL && focus != this) if (focus != NULL && focus != this)
fPrevFocusToken = _get_object_token_(focus); fPrevFocusToken = _get_object_token_(focus);
MakeFocus(); MakeFocus();
@@ -683,12 +691,13 @@ BMenuBar::_StealFocus()
void void
BMenuBar::_RestoreFocus() BMenuBar::_RestoreFocus()
{ {
BWindow *window = Window(); BWindow* window = Window();
if (window != NULL && window->Lock()) { if (window != NULL && window->Lock()) {
BHandler *handler = NULL; BHandler* handler = NULL;
if (fPrevFocusToken != -1 if (fPrevFocusToken != -1
&& gDefaultTokens.GetToken(fPrevFocusToken, B_HANDLER_TOKEN, (void **)&handler) == B_OK) { && gDefaultTokens.GetToken(fPrevFocusToken, B_HANDLER_TOKEN,
BView *view = dynamic_cast<BView *>(handler); (void**)&handler) == B_OK) {
BView* view = dynamic_cast<BView*>(handler);
if (view != NULL && view->Window() == window) if (view != NULL && view->Window() == window)
view->MakeFocus(); view->MakeFocus();
+58 -62
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2008, Haiku, Inc. * Copyright 2001-2009, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -8,6 +8,7 @@
* Ingo Weinhold <bonefish@cs.tu-berlin.de> * Ingo Weinhold <bonefish@cs.tu-berlin.de>
*/ */
#include <MenuField.h> #include <MenuField.h>
#include <stdlib.h> #include <stdlib.h>
@@ -87,10 +88,11 @@ private:
struct BMenuField::LayoutData { struct BMenuField::LayoutData {
LayoutData() LayoutData()
: label_layout_item(NULL), :
menu_bar_layout_item(NULL), label_layout_item(NULL),
previous_height(-1), menu_bar_layout_item(NULL),
valid(false) previous_height(-1),
valid(false)
{ {
} }
@@ -113,9 +115,10 @@ struct BMenuField::LayoutData {
static float kVMargin = 2.0f; static float kVMargin = 2.0f;
BMenuField::BMenuField(BRect frame, const char *name, const char *label, BMenuField::BMenuField(BRect frame, const char* name, const char* label,
BMenu *menu, uint32 resize, uint32 flags) BMenu* menu, uint32 resize, uint32 flags)
: BView(frame, name, resize, flags) :
BView(frame, name, resize, flags)
{ {
CALLED(); CALLED();
@@ -130,9 +133,10 @@ BMenuField::BMenuField(BRect frame, const char *name, const char *label,
} }
BMenuField::BMenuField(BRect frame, const char *name, const char *label, BMenuField::BMenuField(BRect frame, const char* name, const char* label,
BMenu *menu, bool fixedSize, uint32 resize, uint32 flags) BMenu* menu, bool fixedSize, uint32 resize, uint32 flags)
: BView(frame, name, resize, flags) :
BView(frame, name, resize, flags)
{ {
InitObject(label); InitObject(label);
@@ -146,8 +150,9 @@ BMenuField::BMenuField(BRect frame, const char *name, const char *label,
BMenuField::BMenuField(const char* name, const char* label, BMenu* menu, BMenuField::BMenuField(const char* name, const char* label, BMenu* menu,
BMessage* message, uint32 flags) BMessage* message, uint32 flags)
: BView(name, flags | B_FRAME_EVENTS) :
BView(name, flags | B_FRAME_EVENTS)
{ {
InitObject(label); InitObject(label);
@@ -157,9 +162,9 @@ BMenuField::BMenuField(const char* name, const char* label, BMenu* menu,
} }
BMenuField::BMenuField(const char* label, BMenuField::BMenuField(const char* label, BMenu* menu, BMessage* message)
BMenu* menu, BMessage* message) :
: BView(NULL, B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS) BView(NULL, B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS)
{ {
InitObject(label); InitObject(label);
@@ -169,10 +174,11 @@ BMenuField::BMenuField(const char* label,
} }
BMenuField::BMenuField(BMessage *data) BMenuField::BMenuField(BMessage* data)
: BView(data) :
BView(data)
{ {
const char *label = NULL; const char* label = NULL;
data->FindString("_label", &label); data->FindString("_label", &label);
InitObject(label); InitObject(label);
@@ -200,9 +206,8 @@ BMenuField::BMenuField(BMessage *data)
bool dmark = false; bool dmark = false;
data->FindBool("be:dmark", &dmark); data->FindBool("be:dmark", &dmark);
if (_BMCMenuBar_ *menuBar = dynamic_cast<_BMCMenuBar_ *>(fMenuBar)) { if (_BMCMenuBar_* menuBar = dynamic_cast<_BMCMenuBar_*>(fMenuBar))
menuBar->TogglePopUpMarker(dmark); menuBar->TogglePopUpMarker(dmark);
}
} }
@@ -218,8 +223,8 @@ BMenuField::~BMenuField()
} }
BArchivable * BArchivable*
BMenuField::Instantiate(BMessage *data) BMenuField::Instantiate(BMessage* data)
{ {
if (validate_instantiation(data, "BMenuField")) if (validate_instantiation(data, "BMenuField"))
return new BMenuField(data); return new BMenuField(data);
@@ -229,7 +234,7 @@ BMenuField::Instantiate(BMessage *data)
status_t status_t
BMenuField::Archive(BMessage *data, bool deep) const BMenuField::Archive(BMessage* data, bool deep) const
{ {
status_t ret = BView::Archive(data, deep); status_t ret = BView::Archive(data, deep);
@@ -248,9 +253,9 @@ BMenuField::Archive(BMessage *data, bool deep) const
ret = data->AddBool("be:fixeds", true); ret = data->AddBool("be:fixeds", true);
bool dmark = false; bool dmark = false;
if (_BMCMenuBar_ *menuBar = dynamic_cast<_BMCMenuBar_ *>(fMenuBar)) { if (_BMCMenuBar_* menuBar = dynamic_cast<_BMCMenuBar_*>(fMenuBar))
dmark = menuBar->IsPopUpMarkerShown(); dmark = menuBar->IsPopUpMarkerShown();
}
data->AddBool("be:dmark", dmark); data->AddBool("be:dmark", dmark);
return ret; return ret;
@@ -362,7 +367,7 @@ BMenuField::MouseDown(BPoint where)
void void
BMenuField::KeyDown(const char *bytes, int32 numBytes) BMenuField::KeyDown(const char* bytes, int32 numBytes)
{ {
switch (bytes[0]) { switch (bytes[0]) {
case B_SPACE: case B_SPACE:
@@ -405,7 +410,7 @@ BMenuField::MakeFocus(bool state)
void void
BMenuField::MessageReceived(BMessage *msg) BMenuField::MessageReceived(BMessage* msg)
{ {
BView::MessageReceived(msg); BView::MessageReceived(msg);
} }
@@ -429,7 +434,7 @@ BMenuField::MouseUp(BPoint point)
void void
BMenuField::MouseMoved(BPoint point, uint32 code, const BMessage *message) BMenuField::MouseMoved(BPoint point, uint32 code, const BMessage* message)
{ {
BView::MouseMoved(point, code, message); BView::MouseMoved(point, code, message);
} }
@@ -472,21 +477,21 @@ BMenuField::FrameResized(float newWidth, float newHeight)
} }
BMenu * BMenu*
BMenuField::Menu() const BMenuField::Menu() const
{ {
return fMenu; return fMenu;
} }
BMenuBar * BMenuBar*
BMenuField::MenuBar() const BMenuField::MenuBar() const
{ {
return fMenuBar; return fMenuBar;
} }
BMenuItem * BMenuItem*
BMenuField::MenuItem() const BMenuField::MenuItem() const
{ {
return fMenuBar->ItemAt(0); return fMenuBar->ItemAt(0);
@@ -494,7 +499,7 @@ BMenuField::MenuItem() const
void void
BMenuField::SetLabel(const char *label) BMenuField::SetLabel(const char* label)
{ {
if (fLabel) { if (fLabel) {
if (label && strcmp(fLabel, label) == 0) if (label && strcmp(fLabel, label) == 0)
@@ -512,7 +517,7 @@ BMenuField::SetLabel(const char *label)
} }
const char * const char*
BMenuField::Label() const BMenuField::Label() const
{ {
return fLabel; return fLabel;
@@ -598,7 +603,7 @@ BMenuField::Divider() const
void void
BMenuField::ShowPopUpMarker() BMenuField::ShowPopUpMarker()
{ {
if (_BMCMenuBar_ *menuBar = dynamic_cast<_BMCMenuBar_ *>(fMenuBar)) { if (_BMCMenuBar_* menuBar = dynamic_cast<_BMCMenuBar_*>(fMenuBar)) {
menuBar->TogglePopUpMarker(true); menuBar->TogglePopUpMarker(true);
menuBar->Invalidate(); menuBar->Invalidate();
} }
@@ -608,23 +613,23 @@ BMenuField::ShowPopUpMarker()
void void
BMenuField::HidePopUpMarker() BMenuField::HidePopUpMarker()
{ {
if (_BMCMenuBar_ *menuBar = dynamic_cast<_BMCMenuBar_ *>(fMenuBar)) { if (_BMCMenuBar_* menuBar = dynamic_cast<_BMCMenuBar_*>(fMenuBar)) {
menuBar->TogglePopUpMarker(false); menuBar->TogglePopUpMarker(false);
menuBar->Invalidate(); menuBar->Invalidate();
} }
} }
BHandler * BHandler*
BMenuField::ResolveSpecifier(BMessage *message, int32 index, BMenuField::ResolveSpecifier(BMessage* message, int32 index,
BMessage *specifier, int32 form, const char *property) BMessage* specifier, int32 form, const char* property)
{ {
return BView::ResolveSpecifier(message, index, specifier, form, property); return BView::ResolveSpecifier(message, index, specifier, form, property);
} }
status_t status_t
BMenuField::GetSupportedSuites(BMessage *data) BMenuField::GetSupportedSuites(BMessage* data)
{ {
return BView::GetSupportedSuites(data); return BView::GetSupportedSuites(data);
} }
@@ -658,7 +663,7 @@ BMenuField::ResizeToPreferred()
void void
BMenuField::GetPreferredSize(float *_width, float *_height) BMenuField::GetPreferredSize(float* _width, float* _height)
{ {
CALLED(); CALLED();
@@ -854,15 +859,8 @@ void BMenuField::_ReservedMenuField2() {}
void BMenuField::_ReservedMenuField3() {} void BMenuField::_ReservedMenuField3() {}
BMenuField &
BMenuField::operator=(const BMenuField &)
{
return *this;
}
void void
BMenuField::InitObject(const char *label) BMenuField::InitObject(const char* label)
{ {
CALLED(); CALLED();
@@ -945,23 +943,22 @@ BMenuField::DrawLabel(BRect bounds, BRect update)
void void
BMenuField::InitMenu(BMenu *menu) BMenuField::InitMenu(BMenu* menu)
{ {
menu->SetFont(be_plain_font); menu->SetFont(be_plain_font);
int32 index = 0; int32 index = 0;
BMenu *subMenu; BMenu* subMenu;
while ((subMenu = menu->SubmenuAt(index++)) != NULL) while ((subMenu = menu->SubmenuAt(index++)) != NULL)
InitMenu(subMenu); InitMenu(subMenu);
} }
/* static */ /*static*/ int32
int32 BMenuField::_thread_entry(void* arg)
BMenuField::_thread_entry(void *arg)
{ {
return static_cast<BMenuField *>(arg)->_MenuTask(); return static_cast<BMenuField*>(arg)->_MenuTask();
} }
@@ -970,12 +967,12 @@ BMenuField::_MenuTask()
{ {
if (!LockLooper()) if (!LockLooper())
return 0; return 0;
fSelected = true; fSelected = true;
fTransition = true; fTransition = true;
Invalidate(); Invalidate();
UnlockLooper(); UnlockLooper();
bool tracking; bool tracking;
do { do {
snooze(20000); snooze(20000);
@@ -990,7 +987,7 @@ BMenuField::_MenuTask()
if (LockLooper()) { if (LockLooper()) {
fSelected = false; fSelected = false;
fTransition = true; fTransition = true;
Invalidate(); Invalidate();
UnlockLooper(); UnlockLooper();
} }
@@ -1040,11 +1037,11 @@ BMenuField::_InitMenuBar(BMenu* menu, BRect frame, bool fixedSize)
frame.top = kVMargin; frame.top = kVMargin;
frame.right -= kVMargin; frame.right -= kVMargin;
frame.bottom -= kVMargin; frame.bottom -= kVMargin;
TRACE("frame(%.1f, %.1f, %.1f, %.1f) (%.2f, %.2f)\n", TRACE("frame(%.1f, %.1f, %.1f, %.1f) (%.2f, %.2f)\n",
frame.left, frame.top, frame.right, frame.bottom, frame.left, frame.top, frame.right, frame.bottom,
frame.Width(), frame.Height()); frame.Width(), frame.Height());
fMenuBar = new _BMCMenuBar_(frame, fixedSize, this); fMenuBar = new _BMCMenuBar_(frame, fixedSize, this);
} }
@@ -1098,7 +1095,7 @@ BMenuField::_ValidateLayoutData()
// TODO: BMenu::MinSize() is using the ResizeMode() to decide the // TODO: BMenu::MinSize() is using the ResizeMode() to decide the
// minimum width. If the mode is B_FOLLOW_LEFT_RIGHT, it will use the // minimum width. If the mode is B_FOLLOW_LEFT_RIGHT, it will use the
// parent's frame width or window's frame width. So at least the returned // parent's frame width or window's frame width. So at least the returned
// size is wrong, but appearantly it doesn't have much bad effect. // size is wrong, but apparantly it doesn't have much bad effect.
fLayoutData->menu_bar_min = fMenuBar->MinSize(); fLayoutData->menu_bar_min = fMenuBar->MinSize();
TRACE("menu bar min width: %.2f\n", fLayoutData->menu_bar_min.width); TRACE("menu bar min width: %.2f\n", fLayoutData->menu_bar_min.width);
@@ -1117,7 +1114,6 @@ BMenuField::_ValidateLayoutData()
fLayoutData->valid = true; fLayoutData->valid = true;
TRACE("width: %.2f, height: %.2f\n", min.width, min.height); TRACE("width: %.2f, height: %.2f\n", min.width, min.height);
} }
+42 -32
View File
@@ -23,42 +23,45 @@
namespace BPrivate { namespace BPrivate {
class BMenuScroller : public BView { class BMenuScroller : public BView {
public: public:
BMenuScroller(BRect frame); BMenuScroller(BRect frame);
bool IsEnabled() const; bool IsEnabled() const;
void SetEnabled(const bool &enabled); void SetEnabled(bool enabled);
private:
bool fEnabled; private:
bool fEnabled;
}; };
class BMenuFrame : public BView { class BMenuFrame : public BView {
public: public:
BMenuFrame(BMenu *menu); BMenuFrame(BMenu* menu);
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void DetachedFromWindow(); virtual void DetachedFromWindow();
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
private: private:
friend class BMenuWindow; friend class BMenuWindow;
BMenu *fMenu; BMenu* fMenu;
}; };
class UpperScroller : public BMenuScroller { class UpperScroller : public BMenuScroller {
public: public:
UpperScroller(BRect frame); UpperScroller(BRect frame);
virtual void Draw(BRect updateRect);
virtual void Draw(BRect updateRect);
}; };
class LowerScroller : public BMenuScroller { class LowerScroller : public BMenuScroller {
public: public:
LowerScroller(BRect frame); LowerScroller(BRect frame);
virtual void Draw(BRect updateRect);
virtual void Draw(BRect updateRect);
}; };
@@ -72,7 +75,8 @@ const int kScrollerHeight = 10;
BMenuScroller::BMenuScroller(BRect frame) BMenuScroller::BMenuScroller(BRect frame)
: BView(frame, "menu scroller", 0, B_WILL_DRAW | B_FRAME_EVENTS), :
BView(frame, "menu scroller", 0, B_WILL_DRAW | B_FRAME_EVENTS),
fEnabled(false) fEnabled(false)
{ {
SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR));
@@ -87,7 +91,7 @@ BMenuScroller::IsEnabled() const
void void
BMenuScroller::SetEnabled(const bool &enabled) BMenuScroller::SetEnabled(bool enabled)
{ {
fEnabled = enabled; fEnabled = enabled;
} }
@@ -112,15 +116,16 @@ UpperScroller::Draw(BRect updateRect)
// Draw the upper arrow. // Draw the upper arrow.
if (IsEnabled()) if (IsEnabled())
SetHighColor(0, 0, 0); SetHighColor(0, 0, 0);
else else {
SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
B_DARKEN_2_TINT)); B_DARKEN_2_TINT));
}
FillRect(Bounds(), B_SOLID_LOW); FillRect(Bounds(), B_SOLID_LOW);
FillTriangle(BPoint(middle, (kScrollerHeight / 2) - 3), FillTriangle(BPoint(middle, (kScrollerHeight / 2) - 3),
BPoint(middle + 5, (kScrollerHeight / 2) + 2), BPoint(middle + 5, (kScrollerHeight / 2) + 2),
BPoint(middle - 5, (kScrollerHeight / 2) + 2)); BPoint(middle - 5, (kScrollerHeight / 2) + 2));
} }
@@ -143,17 +148,18 @@ LowerScroller::Draw(BRect updateRect)
// Draw the lower arrow. // Draw the lower arrow.
if (IsEnabled()) if (IsEnabled())
SetHighColor(0, 0, 0); SetHighColor(0, 0, 0);
else else {
SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
B_DARKEN_2_TINT)); B_DARKEN_2_TINT));
}
FillRect(frame, B_SOLID_LOW); FillRect(frame, B_SOLID_LOW);
float middle = Bounds().right / 2; float middle = Bounds().right / 2;
FillTriangle(BPoint(middle, frame.bottom - (kScrollerHeight / 2) + 3), FillTriangle(BPoint(middle, frame.bottom - (kScrollerHeight / 2) + 3),
BPoint(middle + 5, frame.bottom - (kScrollerHeight / 2) - 2), BPoint(middle + 5, frame.bottom - (kScrollerHeight / 2) - 2),
BPoint(middle - 5, frame.bottom - (kScrollerHeight / 2) - 2)); BPoint(middle - 5, frame.bottom - (kScrollerHeight / 2) - 2));
} }
@@ -161,7 +167,8 @@ LowerScroller::Draw(BRect updateRect)
BMenuFrame::BMenuFrame(BMenu *menu) BMenuFrame::BMenuFrame(BMenu *menu)
: BView(BRect(0, 0, 1, 1), "menu frame", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), :
BView(BRect(0, 0, 1, 1), "menu frame", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
fMenu(menu) fMenu(menu)
{ {
} }
@@ -205,8 +212,8 @@ BMenuFrame::Draw(BRect updateRect)
// TODO: Review this as it's a bit hacky. // TODO: Review this as it's a bit hacky.
// Menu has a size of 0, 0, since there are no items in it. // Menu has a size of 0, 0, since there are no items in it.
// So the BMenuFrame class has to fake it and draw an empty item. // So the BMenuFrame class has to fake it and draw an empty item.
// Note that we can't add a real "empty" item because then we couldn't // Note that we can't add a real "empty" item because then we
// tell if the item was added by us or not. // couldn't tell if the item was added by us or not.
// See also BMenu::UpdateWindowViewSize() // See also BMenu::UpdateWindowViewSize()
SetHighColor(ui_color(B_MENU_BACKGROUND_COLOR)); SetHighColor(ui_color(B_MENU_BACKGROUND_COLOR));
SetLowColor(HighColor()); SetLowColor(HighColor());
@@ -215,8 +222,11 @@ BMenuFrame::Draw(BRect updateRect)
font_height height; font_height height;
GetFontHeight(&height); GetFontHeight(&height);
SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DISABLED_LABEL_TINT)); SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
BPoint where((Bounds().Width() - fMenu->StringWidth(kEmptyMenuLabel)) / 2, ceilf(height.ascent + 1)); B_DISABLED_LABEL_TINT));
BPoint where(
(Bounds().Width() - fMenu->StringWidth(kEmptyMenuLabel)) / 2,
ceilf(height.ascent + 1));
DrawString(kEmptyMenuLabel, where); DrawString(kEmptyMenuLabel, where);
} }