1ed7c19b5SJohn Scipione/* 2819863d8SJohn Scipione * Copyright 2013 Haiku, Inc. All rights reserved. 3ed7c19b5SJohn Scipione * Distributed under the terms of the MIT License. 4ed7c19b5SJohn Scipione * 5ed7c19b5SJohn Scipione * Authors: 6ed7c19b5SJohn Scipione * John Scipione, jscipione@gmail.com 7ed7c19b5SJohn Scipione * 8ed7c19b5SJohn Scipione * Corresponds to: 9ed7c19b5SJohn Scipione * headers/os/interface/MenuBar.h hrev46323 10ed7c19b5SJohn Scipione * src/kits/interface/MenuBar.cpp hrev46323 11ed7c19b5SJohn Scipione */ 12ed7c19b5SJohn Scipione 13ed7c19b5SJohn Scipione 14ed7c19b5SJohn Scipione/*! 15ed7c19b5SJohn Scipione \file MenuBar.h 16ed7c19b5SJohn Scipione \ingroup interface 17ed7c19b5SJohn Scipione \ingroup libbe 18d7d2ff5bSJohn Scipione \brief BMenuBar class definition and support structures. 19ed7c19b5SJohn Scipione*/ 20ed7c19b5SJohn Scipione 21ed7c19b5SJohn Scipione 22ed7c19b5SJohn Scipione/*! 23ed7c19b5SJohn Scipione \enum menu_bar_border 24ed7c19b5SJohn Scipione \ingroup interface 25ed7c19b5SJohn Scipione 26ed7c19b5SJohn Scipione Menu bar border style constants. 27ed7c19b5SJohn Scipione 28ed7c19b5SJohn Scipione \see BMenuBar::SetBorder() 2947852bffSJohn Scipione 3047852bffSJohn Scipione \since BeOS R3 31ed7c19b5SJohn Scipione*/ 32ed7c19b5SJohn Scipione 33ed7c19b5SJohn Scipione 34ed7c19b5SJohn Scipione/*! 35ed7c19b5SJohn Scipione \var menu_bar_border B_BORDER_FRAME 36ed7c19b5SJohn Scipione 37ed7c19b5SJohn Scipione The border is drawn around the entire menu bar. 3847852bffSJohn Scipione 3947852bffSJohn Scipione \since BeOS R3 40ed7c19b5SJohn Scipione*/ 41ed7c19b5SJohn Scipione 42ed7c19b5SJohn Scipione 43ed7c19b5SJohn Scipione/*! 44ed7c19b5SJohn Scipione \var menu_bar_border B_BORDER_CONTENTS 45ed7c19b5SJohn Scipione 46ed7c19b5SJohn Scipione The border is drawn around the list of items. 47ed7c19b5SJohn Scipione 4847852bffSJohn Scipione \since BeOS R3 4947852bffSJohn Scipione*/ 50ed7c19b5SJohn Scipione 51ed7c19b5SJohn Scipione 52ed7c19b5SJohn Scipione/*! 53ed7c19b5SJohn Scipione \var menu_bar_border B_BORDER_EACH_ITEM 54ed7c19b5SJohn Scipione 55ed7c19b5SJohn Scipione The border is drawn around each individual item. 5647852bffSJohn Scipione 5747852bffSJohn Scipione \since BeOS R3 58ed7c19b5SJohn Scipione*/ 59ed7c19b5SJohn Scipione 60ed7c19b5SJohn Scipione 61ed7c19b5SJohn Scipione/*! 62ed7c19b5SJohn Scipione \class BMenuBar 63ed7c19b5SJohn Scipione \ingroup interface 64ed7c19b5SJohn Scipione \ingroup libbe 65ed7c19b5SJohn Scipione \brief A window's root menu. 66ed7c19b5SJohn Scipione 67ed7c19b5SJohn Scipione A menu bar, if a window has one, is typically drawn across the top of the 68ed7c19b5SJohn Scipione window just below the tab and a window typically has just a single menu bar, 69ed7c19b5SJohn Scipione although this is up to you. 70ed7c19b5SJohn Scipione 71ed7c19b5SJohn Scipione One menu bar attached to a window is considered to be the "key" menu bar 72ed7c19b5SJohn Scipione that can be navigated by the user using the keyboard. The last menu bar 73ed7c19b5SJohn Scipione attached to a window is automatically set as the key menu bar for the 74ed7c19b5SJohn Scipione window. To override this behavior and set a different key menu bar use the 75ed7c19b5SJohn Scipione BWindow::SetKeyMenuBar() method. 76ed7c19b5SJohn Scipione 77ed7c19b5SJohn Scipione When either the \key{Menu} key or \key{Command}+\key{Esc} keys are pressed 78*44b87466SJohn Scipione the key menu bar opens and focuses its first menu item, typically a BMenu. 79ed7c19b5SJohn Scipione Once the menu bar is open the user can navigate around the attached menus 80ed7c19b5SJohn Scipione and menu items using the arrow keys. 81ed7c19b5SJohn Scipione 82ed7c19b5SJohn Scipione Like a BMenu, a BMenuBar object starts without any items attached to it, 83ed7c19b5SJohn Scipione you'll need to call AddItem() or AddList() to add some. The top-level items 84ed7c19b5SJohn Scipione in a menu bar are typically menus which have menu items and menus added to 85ed7c19b5SJohn Scipione them in turn. 8647852bffSJohn Scipione 8747852bffSJohn Scipione \since BeOS R3 88ed7c19b5SJohn Scipione*/ 89ed7c19b5SJohn Scipione 90ed7c19b5SJohn Scipione 91ed7c19b5SJohn Scipione/*! 92ed7c19b5SJohn Scipione \fn BMenuBar::BMenuBar(BRect frame, const char* name, uint32 resizingMode, 93ed7c19b5SJohn Scipione menu_layout layout, bool resizeToFit) 94ed7c19b5SJohn Scipione \brief Create a new BMenuBar object. 95ed7c19b5SJohn Scipione 96ed7c19b5SJohn Scipione The default resizing mode, \c B_FOLLOW_LEFT_RIGHT | \c B_FOLLOW_TOP is 97ed7c19b5SJohn Scipione meant to be used by a typical menu bar that is positioned along the top 98ed7c19b5SJohn Scipione edge of a window. This resizing mode allows the menu bar to resize itself 99ed7c19b5SJohn Scipione based on changes to the window's width while keeping it attached to the 100ed7c19b5SJohn Scipione top of the window frame. 101ed7c19b5SJohn Scipione 102ed7c19b5SJohn Scipione For menu bars in \c B_ITEMS_IN_ROW layout the height is automatically 103ed7c19b5SJohn Scipione set to be the height of a single item, while menus bars in 104ed7c19b5SJohn Scipione \c B_ITEMS_IN_COLUMN layout the width is automatically set to be the width 105ed7c19b5SJohn Scipione of the widest item. 106ed7c19b5SJohn Scipione 107ed7c19b5SJohn Scipione The width of a menu bar is set equal to the width of its parent for menu 108ed7c19b5SJohn Scipione bars in \c B_ITEMS_IN_ROW layout and a \a resizingMode mask that includes 109ed7c19b5SJohn Scipione \c B_FOLLOW_LEFT_RIGHT so that the menu bar will always be as wide as its 110ed7c19b5SJohn Scipione attached window. 111ed7c19b5SJohn Scipione 112ed7c19b5SJohn Scipione Likewise, the height of a menu bar is set equal to the height of its parent 113ed7c19b5SJohn Scipione for menu bars in \c B_ITEMS_IN_COLUMN layout and a \a resizingMode mask that 114ed7c19b5SJohn Scipione includes \c B_FOLLOW_TOP_BOTTOM so that the menu bar will always be as high 115ed7c19b5SJohn Scipione as its attached window. 116ed7c19b5SJohn Scipione 117ed7c19b5SJohn Scipione When \a resizeToFit is set to \c true, as is the default, the \a frame 118ed7c19b5SJohn Scipione rectangle determines only where the menu bar is located, not its size. 119ed7c19b5SJohn Scipione If the \a layout is set to \c B_ITEMS_IN_MATRIX the \a resizeToFit flag 120ed7c19b5SJohn Scipione should be set to \c false. 121ed7c19b5SJohn Scipione 122ed7c19b5SJohn Scipione \param frame The \a frame rectangle to create the menu bar in. 123ed7c19b5SJohn Scipione \param name The \a name of the menu bar, used internally only. 124ed7c19b5SJohn Scipione \param resizingMode The resizing mode flags, see BView for more details. 125ed7c19b5SJohn Scipione \param layout The menu layout, possibilities include: 126ed7c19b5SJohn Scipione - \c B_ITEMS_IN_ROW items are displayed in a single row, 127ed7c19b5SJohn Scipione - \c B_ITEMS_IN_COLUMN items are displayed in a single column, 128ed7c19b5SJohn Scipione - \c B_ITEMS_IN_MATRIX items are displayed in a custom matrix. 129ed7c19b5SJohn Scipione \param resizeToFit Whether or not the menu bar should automatically resize 130ed7c19b5SJohn Scipione itself to fit its contents, this will not work in 131ed7c19b5SJohn Scipione \c B_ITEMS_IN_MATRIX layout. 13247852bffSJohn Scipione 13347852bffSJohn Scipione \since BeOS R3 134ed7c19b5SJohn Scipione*/ 135ed7c19b5SJohn Scipione 136ed7c19b5SJohn Scipione 137ed7c19b5SJohn Scipione/*! 138ed7c19b5SJohn Scipione \fn BMenuBar::BMenuBar(const char* name, menu_layout layout, uint32 flags) 139ed7c19b5SJohn Scipione \brief Create a new BMenuBar object suitable to use with the layout APIs. 140ed7c19b5SJohn Scipione 141ed7c19b5SJohn Scipione \param name The \a name of the menu bar, used internally only. 142ed7c19b5SJohn Scipione \param flags The view \a flags, see BView for more details. 143ed7c19b5SJohn Scipione \param layout The menu layout, possibilities include: 144ed7c19b5SJohn Scipione - \c B_ITEMS_IN_ROW items are displayed in a single row, 145ed7c19b5SJohn Scipione - \c B_ITEMS_IN_COLUMN items are displayed in a single column, 146ed7c19b5SJohn Scipione - \c B_ITEMS_IN_MATRIX items are displayed in a custom matrix. 14747852bffSJohn Scipione 14847852bffSJohn Scipione \since Haiku R1 149ed7c19b5SJohn Scipione*/ 150ed7c19b5SJohn Scipione 151ed7c19b5SJohn Scipione 152ed7c19b5SJohn Scipione/*! 153ed7c19b5SJohn Scipione \fn BMenuBar::BMenuBar(BMessage* archive) 154ed7c19b5SJohn Scipione \brief Archive constructor. 155ed7c19b5SJohn Scipione 156ed7c19b5SJohn Scipione \param archive The message data to construct the menu from. 15747852bffSJohn Scipione 15847852bffSJohn Scipione \since BeOS R3 159ed7c19b5SJohn Scipione*/ 160ed7c19b5SJohn Scipione 161ed7c19b5SJohn Scipione 162ed7c19b5SJohn Scipione/*! 163ed7c19b5SJohn Scipione \fn BMenuBar::~BMenuBar() 164ed7c19b5SJohn Scipione \brief Destructor. 165ed7c19b5SJohn Scipione 166ed7c19b5SJohn Scipione Also frees the memory used by any attached menus and menu items. 16747852bffSJohn Scipione 16847852bffSJohn Scipione \since BeOS R3 169ed7c19b5SJohn Scipione*/ 170ed7c19b5SJohn Scipione 171ed7c19b5SJohn Scipione 172ed7c19b5SJohn Scipione/*! 17347852bffSJohn Scipione \name Archiving 17447852bffSJohn Scipione*/ 17547852bffSJohn Scipione 17647852bffSJohn Scipione 17747852bffSJohn Scipione//! @{ 17847852bffSJohn Scipione 17947852bffSJohn Scipione 18047852bffSJohn Scipione/*! 181ed7c19b5SJohn Scipione \fn BArchivable* BMenuBar::Instantiate(BMessage* data) 182ed7c19b5SJohn Scipione \brief Creates a new BMenuBar object from an \a archive message. 183ed7c19b5SJohn Scipione 184ed7c19b5SJohn Scipione \returns A newly created BMenuBar object or \c NULL if the message 185ed7c19b5SJohn Scipione doesn't contain an archived BMenuBar. 18647852bffSJohn Scipione 18747852bffSJohn Scipione \since BeOS R3 188ed7c19b5SJohn Scipione*/ 189ed7c19b5SJohn Scipione 190ed7c19b5SJohn Scipione 191ed7c19b5SJohn Scipione/*! 192ed7c19b5SJohn Scipione \fn status_t BMenuBar::Archive(BMessage* data, bool deep) const 193ed7c19b5SJohn Scipione \brief Archives the the BMenuBar object into the \a data message. 194ed7c19b5SJohn Scipione 195ed7c19b5SJohn Scipione \param data A pointer to the BMessage to archive the object into. 196ed7c19b5SJohn Scipione \param deep Whether or not to archive attached menu items as well. 197ed7c19b5SJohn Scipione 198ed7c19b5SJohn Scipione \return A status code, \c B_OK if everything went well or an error code 199ed7c19b5SJohn Scipione otherwise. 200ed7c19b5SJohn Scipione \retval B_OK The object was archived successfully. 201ed7c19b5SJohn Scipione \retval B_NO_MEMORY Ran out of memory while archiving the object. 20247852bffSJohn Scipione 20347852bffSJohn Scipione \since BeOS R3 204ed7c19b5SJohn Scipione*/ 205ed7c19b5SJohn Scipione 206ed7c19b5SJohn Scipione 20747852bffSJohn Scipione//! @} 20847852bffSJohn Scipione 20947852bffSJohn Scipione 21047852bffSJohn Scipione/*! 21147852bffSJohn Scipione \name Hook Methods 21247852bffSJohn Scipione*/ 21347852bffSJohn Scipione 21447852bffSJohn Scipione 21547852bffSJohn Scipione//! @{ 21647852bffSJohn Scipione 21747852bffSJohn Scipione 218ed7c19b5SJohn Scipione/*! 219ed7c19b5SJohn Scipione \fn void BMenuBar::AttachedToWindow() 220ed7c19b5SJohn Scipione \brief Sets this as the key menubar for the window, lays out the menu items 221ed7c19b5SJohn Scipione and resizes the menu to fit. 222ed7c19b5SJohn Scipione 223ed7c19b5SJohn Scipione \see BWindow::SetKeyMenuBar() 22447852bffSJohn Scipione 22547852bffSJohn Scipione \since BeOS R3 226ed7c19b5SJohn Scipione*/ 227ed7c19b5SJohn Scipione 228ed7c19b5SJohn Scipione 229ed7c19b5SJohn Scipione/*! 230ed7c19b5SJohn Scipione \fn void BMenuBar::FrameResized(float newWidth, float newHeight) 231ed7c19b5SJohn Scipione \brief Hook method that gets called when the menu bar is resized. 232ed7c19b5SJohn Scipione 233ed7c19b5SJohn Scipione Redraws the affected borders. 234ed7c19b5SJohn Scipione 23547852bffSJohn Scipione \copydetails BView::FrameResized() 236ed7c19b5SJohn Scipione*/ 237ed7c19b5SJohn Scipione 238ed7c19b5SJohn Scipione 239ed7c19b5SJohn Scipione/*! 240ed7c19b5SJohn Scipione \fn void BMenuBar::Draw(BRect updateRect) 241ed7c19b5SJohn Scipione \brief Draws the menu bar. 242ed7c19b5SJohn Scipione 243ed7c19b5SJohn Scipione \param updateRect The area to draw in. 24447852bffSJohn Scipione 24547852bffSJohn Scipione \since BeOS R3 246ed7c19b5SJohn Scipione*/ 247ed7c19b5SJohn Scipione 248ed7c19b5SJohn Scipione 249ed7c19b5SJohn Scipione/*! 250ed7c19b5SJohn Scipione \fn void BMenuBar::MouseDown(BPoint where) 251ed7c19b5SJohn Scipione \brief Hook method that is called when a mouse button is pressed. 252ed7c19b5SJohn Scipione 253ed7c19b5SJohn Scipione Right clicking on a menu bar sends the window to back or brings it to front. 254ed7c19b5SJohn Scipione 25547852bffSJohn Scipione \copydetails BView::MouseDown() 256ed7c19b5SJohn Scipione*/ 257ed7c19b5SJohn Scipione 258ed7c19b5SJohn Scipione 25947852bffSJohn Scipione//! @} 26047852bffSJohn Scipione 26147852bffSJohn Scipione 262ed7c19b5SJohn Scipione/*! 263ed7c19b5SJohn Scipione \fn void BMenuBar::SetBorder(menu_bar_border border) 26447852bffSJohn Scipione \brief Specifies how the menu bar border is drawn. 265ed7c19b5SJohn Scipione 266ed7c19b5SJohn Scipione The default is \c B_BORDER_FRAME. 267ed7c19b5SJohn Scipione 268ed7c19b5SJohn Scipione \param border Options include: 269ed7c19b5SJohn Scipione - \c B_BORDER_FRAME The border is drawn around the entire menu bar. 270ed7c19b5SJohn Scipione - \c B_BORDER_CONTENTS The border is drawn around the list of items. 271ed7c19b5SJohn Scipione - \c B_BORDER_EACH_ITEM The border is drawn around each individual 272ed7c19b5SJohn Scipione item. 27347852bffSJohn Scipione 27447852bffSJohn Scipione \since BeOS R3 275ed7c19b5SJohn Scipione*/ 276ed7c19b5SJohn Scipione 277ed7c19b5SJohn Scipione 278ed7c19b5SJohn Scipione/*! 279ed7c19b5SJohn Scipione \fn menu_bar_border BMenuBar::Border() const 280ed7c19b5SJohn Scipione \brief Returns the currently set border style. 281ed7c19b5SJohn Scipione 28234ce2cefSJohn Scipione \see BMenuBar::SetBorder() for details. 28347852bffSJohn Scipione 28447852bffSJohn Scipione \since BeOS R3 285ed7c19b5SJohn Scipione*/ 286