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