17192a931SJohn Scipione/* 2819863d8SJohn Scipione * Copyright 2013 Haiku, Inc. All rights reserved. 37192a931SJohn Scipione * Distributed under the terms of the MIT License. 47192a931SJohn Scipione * 57192a931SJohn Scipione * Authors: 67192a931SJohn Scipione * John Scipione, jscipione@gmail.com 77192a931SJohn Scipione * 87192a931SJohn Scipione * Corresponds to: 97192a931SJohn Scipione * headers/os/interface/PopUpMenu.h hrev46360 107192a931SJohn Scipione * src/kits/interface/PopUpMenu.cpp hrev46360 117192a931SJohn Scipione */ 127192a931SJohn Scipione 137192a931SJohn Scipione 147192a931SJohn Scipione/*! 157192a931SJohn Scipione \file PopUpMenu.h 167192a931SJohn Scipione \ingroup interface 177192a931SJohn Scipione \ingroup libbe 187192a931SJohn Scipione \brief BPopUpMenu class definition and support structures. 197192a931SJohn Scipione*/ 207192a931SJohn Scipione 217192a931SJohn Scipione 227192a931SJohn Scipione/*! 237192a931SJohn Scipione \class BPopUpMenu 247192a931SJohn Scipione \ingroup interface 257192a931SJohn Scipione \ingroup libbe 267192a931SJohn Scipione \brief Displays a pop-up menu. 277192a931SJohn Scipione 287192a931SJohn Scipione A BPopUpMenu is typically used to display a limited set of 297192a931SJohn Scipione mutually-exclusive choices rather than as part of a deeply nested 307192a931SJohn Scipione menu hierarchy. A BPopUpMenu is similar to a BMenu but has a few 317192a931SJohn Scipione additional methods to make it easier to use the menu as a stand-alone 327192a931SJohn Scipione menu and to manage the object's lifetime. 337192a931SJohn Scipione 347192a931SJohn Scipione Pop-up menus are used either as a stand-alone menu, usually as 357192a931SJohn Scipione a context menu activated by \c B_SECONDARY_MOUSE_BUTTON, or 367192a931SJohn Scipione as a menu attached to a BMenuField or BMenuBar. 377192a931SJohn Scipione 387192a931SJohn Scipione If the pop-up menu is used as a stand-alone menu, the Go() method 397192a931SJohn Scipione controls how and where the menu pops up and provides several options 407192a931SJohn Scipione for how the pop-up menu works. 417192a931SJohn Scipione 427192a931SJohn Scipione Once Go() returns the BPopUpMenu object should be destroyed. You can call 437192a931SJohn Scipione SetAsyncAutoDestruct() passing \c true to destroy the object automatically 447192a931SJohn Scipione when it returns. This is not advisable if the \a deliversMessage parameter 457192a931SJohn Scipione of Go() is set \c false because you'll want to examine the return value 467192a931SJohn Scipione before destroying the BPopUpMenu object. 477192a931SJohn Scipione 487192a931SJohn Scipione If the pop-up menu is used as part of a BMenuField or BMenuBar it behaves 497192a931SJohn Scipione almost exactly like a BMenu would, but, the menu pops up directly under the 507192a931SJohn Scipione mouse pointer instead of underneath the BMenuBar or BMenuField. 51*47852bffSJohn Scipione 52*47852bffSJohn Scipione \since BeOS R3 537192a931SJohn Scipione*/ 547192a931SJohn Scipione 557192a931SJohn Scipione 567192a931SJohn Scipione/*! 577192a931SJohn Scipione \fn BPopUpMenu::BPopUpMenu(const char* name, bool radioMode, 587192a931SJohn Scipione bool labelFromMarked, menu_layout layout) 597192a931SJohn Scipione \brief Creates a new BPopUpMenu object. 607192a931SJohn Scipione 617192a931SJohn Scipione \attention A BPopUpMenu should never be set to \a B_ITEMS_IN_MATRIX 627192a931SJohn Scipione layout. The menu is automatically resized so that its 637192a931SJohn Scipione menu items will fit exactly in the menu. 647192a931SJohn Scipione 657192a931SJohn Scipione \param name The menu's name, serves as a label for submenus. 667192a931SJohn Scipione \param radioMode Whether or not the menu is in radio mode, default is 677192a931SJohn Scipione \c true. 687192a931SJohn Scipione \param labelFromMarked Whether or not the menu is in label-from-marked mode, 697192a931SJohn Scipione default is \c true. 707192a931SJohn Scipione \param layout The menu layout, possibilities include: 717192a931SJohn Scipione - \c B_ITEMS_IN_ROW items are displayed in a single row, 727192a931SJohn Scipione - \c B_ITEMS_IN_COLUMN items are displayed in a single column, 737192a931SJohn Scipione the default layout. 747192a931SJohn Scipione 757192a931SJohn Scipione \see BMenu::SetRadioMode() 767192a931SJohn Scipione \see BMenu::SetLabelFromMarked() 77*47852bffSJohn Scipione 78*47852bffSJohn Scipione \since BeOS R3 797192a931SJohn Scipione*/ 807192a931SJohn Scipione 817192a931SJohn Scipione 827192a931SJohn Scipione/*! 837192a931SJohn Scipione \fn BPopUpMenu::BPopUpMenu(BMessage* archive) 847192a931SJohn Scipione \brief Archive constructor. 857192a931SJohn Scipione 867192a931SJohn Scipione \param archive The message data to construct the pop-up menu from. 87*47852bffSJohn Scipione 88*47852bffSJohn Scipione \since BeOS R3 89*47852bffSJohn Scipione*/ 90*47852bffSJohn Scipione 91*47852bffSJohn Scipione 92*47852bffSJohn Scipione/*! 93*47852bffSJohn Scipione \fn BPopUpMenu& BPopUpMenu::operator=(const BPopUpMenu& other) 94*47852bffSJohn Scipione \brief Assignment overload method. 95*47852bffSJohn Scipione 96*47852bffSJohn Scipione \param other The BPopUpMenu object to assign from. 97*47852bffSJohn Scipione 98*47852bffSJohn Scipione \return The newly assigned BPopUpMenu object. 99*47852bffSJohn Scipione 100*47852bffSJohn Scipione \since BeOS R3 1017192a931SJohn Scipione*/ 1027192a931SJohn Scipione 1037192a931SJohn Scipione 1047192a931SJohn Scipione/*! 1057192a931SJohn Scipione \fn BPopUpMenu::~BPopUpMenu() 1067192a931SJohn Scipione \brief Destructor method. 1077192a931SJohn Scipione 1087192a931SJohn Scipione Also frees the memory used by any attached menu items. 109*47852bffSJohn Scipione 110*47852bffSJohn Scipione \since BeOS R3 1117192a931SJohn Scipione*/ 1127192a931SJohn Scipione 1137192a931SJohn Scipione 1147192a931SJohn Scipione/*! 115*47852bffSJohn Scipione \name Archiving 116*47852bffSJohn Scipione*/ 117*47852bffSJohn Scipione 118*47852bffSJohn Scipione 119*47852bffSJohn Scipione//! @{ 120*47852bffSJohn Scipione 121*47852bffSJohn Scipione 122*47852bffSJohn Scipione/*! 1237192a931SJohn Scipione \fn status_t BPopUpMenu::Archive(BMessage* data, bool deep) const 1247192a931SJohn Scipione \brief Archives the the BMenuField object into the \a data message. 1257192a931SJohn Scipione 1267192a931SJohn Scipione \param data A pointer to the BMessage to archive the object into. 1277192a931SJohn Scipione \param deep Whether or not to archive attached menu items as well. 1287192a931SJohn Scipione 1297192a931SJohn Scipione \return A status code, \c B_OK if everything went well or an error code 1307192a931SJohn Scipione otherwise. 1317192a931SJohn Scipione \retval B_OK The object was archived successfully. 1327192a931SJohn Scipione \retval B_NO_MEMORY Ran out of memory while archiving the object. 133*47852bffSJohn Scipione 134*47852bffSJohn Scipione \since BeOS R3 1357192a931SJohn Scipione*/ 1367192a931SJohn Scipione 1377192a931SJohn Scipione 1387192a931SJohn Scipione/*! 1397192a931SJohn Scipione \fn BArchivable* BPopUpMenu::Instantiate(BMessage* data) 1407192a931SJohn Scipione \brief Creates a new BPopUpMenu object from the \a data message. 1417192a931SJohn Scipione 1427192a931SJohn Scipione \returns A newly created BPopUpMenu object or \c NULL if the message 1437192a931SJohn Scipione doesn't contain an archived BPopUpMenu. 144*47852bffSJohn Scipione 145*47852bffSJohn Scipione \since BeOS R3 1467192a931SJohn Scipione*/ 1477192a931SJohn Scipione 1487192a931SJohn Scipione 149*47852bffSJohn Scipione//! @} 150*47852bffSJohn Scipione 151*47852bffSJohn Scipione 1527192a931SJohn Scipione/*! 1537192a931SJohn Scipione \fn BMenuItem* BPopUpMenu::Go(BPoint where, bool deliversMessage, 1547192a931SJohn Scipione bool openAnyway, bool async) 1557192a931SJohn Scipione \brief Places the menu on screen. 1567192a931SJohn Scipione 1577192a931SJohn Scipione \param where The location to open the left-top-corner of the pop-up menu 1587192a931SJohn Scipione in the screen's coordinate system. 1597192a931SJohn Scipione \param deliversMessage if \c true, the menu item posts a message to its 1607192a931SJohn Scipione target as it normally would when selected by the user. 1617192a931SJohn Scipione If \a deliversMessage is \c false no message is sent and you are 1627192a931SJohn Scipione expected to decide what action to take based on the return value. 1637192a931SJohn Scipione \param openAnyway If \c true, the pop-up menu will stay open even once the 1647192a931SJohn Scipione user has released the mouse button. To dismiss the menu, either a 1657192a931SJohn Scipione menu item must be selected or it must be dismissed programmatically. 1667192a931SJohn Scipione \param async If \c true the menu will return \c NULL immediately, if 1677192a931SJohn Scipione \c false the menu will not return until a menu item is selected 1687192a931SJohn Scipione or it is dismissed by the user. If a menu item was selected a 1697192a931SJohn Scipione pointer to the menu item is returned, if not, \c NULL is returned. 170*47852bffSJohn Scipione 171*47852bffSJohn Scipione \since BeOS R3 1727192a931SJohn Scipione*/ 1737192a931SJohn Scipione 1747192a931SJohn Scipione 1757192a931SJohn Scipione/*! 1767192a931SJohn Scipione \fn BMenuItem* BPopUpMenu::Go(BPoint where, bool deliversMessage, 1777192a931SJohn Scipione bool openAnyway, BRect clickToOpen, bool async) 1787192a931SJohn Scipione \brief Places the menu on screen, with \a clickToOpen option. 1797192a931SJohn Scipione 1807192a931SJohn Scipione The \a clickToOpen rectangle should be specified in the screen's 1817192a931SJohn Scipione coordinate system. \a openAnyway must be set \c true for the \a clickToOpen 1827192a931SJohn Scipione rectangle to work. 1837192a931SJohn Scipione 1847192a931SJohn Scipione \param where The location to open the left-top-corner of the pop-up menu 1857192a931SJohn Scipione in the screen's coordinate system. 1867192a931SJohn Scipione \param deliversMessage if \c true, the menu item posts a message to its 1877192a931SJohn Scipione target as it normally would when selected by the user. 1887192a931SJohn Scipione If \a deliversMessage is \c false no message is sent and you are 1897192a931SJohn Scipione expected to decide what action to take based on the return value. 1907192a931SJohn Scipione \param openAnyway If \c true, the pop-up menu will stay open even once the 1917192a931SJohn Scipione user has released the mouse button. To dismiss the menu, either a 1927192a931SJohn Scipione menu item must be selected or it must be dismissed programmatically. 1937192a931SJohn Scipione \param clickToOpen If the user releases the mouse button while the cursor 1947192a931SJohn Scipione is inside the \a clickToOpen rectangle the menu is kept on-screen, 1957192a931SJohn Scipione if the cursor is located outside of the \a clickToOpen rectangle 1967192a931SJohn Scipione the menu is removed from the screen and Go() returns. 1977192a931SJohn Scipione \param async If \c true the menu will return \c NULL immediately, if 1987192a931SJohn Scipione \c false the menu will not return until a menu item is selected 1997192a931SJohn Scipione or it is dismissed by the user. If a menu item was selected a 2007192a931SJohn Scipione pointer to the menu item is returned, if not, \c NULL is returned. 201*47852bffSJohn Scipione 202*47852bffSJohn Scipione \since BeOS R3 2037192a931SJohn Scipione*/ 2047192a931SJohn Scipione 2057192a931SJohn Scipione 2067192a931SJohn Scipione/*! 2077192a931SJohn Scipione \fn void BPopUpMenu::SetAsyncAutoDestruct(bool on) 2087192a931SJohn Scipione \brief Indicates whether or not the BPopUpMenu will delete itself after 2097192a931SJohn Scipione closing, async-auto-destruct mode is set to \c false by default. 2107192a931SJohn Scipione 2117192a931SJohn Scipione \param on \c true to turn async-auto-destruct mode on, \c false to turn 2127192a931SJohn Scipione async-auto-destruct mode off. 213*47852bffSJohn Scipione 214*47852bffSJohn Scipione \since BeOS R5 2157192a931SJohn Scipione*/ 2167192a931SJohn Scipione 2177192a931SJohn Scipione 2187192a931SJohn Scipione/*! 2197192a931SJohn Scipione \fn bool BPopUpMenu::AsyncAutoDestruct() const 2207192a931SJohn Scipione \brief Returns the current async-auto-destruct setting. 2217192a931SJohn Scipione 2227192a931SJohn Scipione \return \c true if async-auto-destruct mode is turned on, \c false if 2237192a931SJohn Scipione async-auto-destruct mode is turned off. 2247192a931SJohn Scipione 2257192a931SJohn Scipione \see SetAsyncAutoDestruct() 226*47852bffSJohn Scipione 227*47852bffSJohn Scipione \since BeOS R5 2287192a931SJohn Scipione*/ 2297192a931SJohn Scipione 2307192a931SJohn Scipione 2317192a931SJohn Scipione/*! 2327192a931SJohn Scipione \fn BPoint BPopUpMenu::ScreenLocation() 2337192a931SJohn Scipione \brief Returns where the pop-up menu will appear on screen when it is 2347192a931SJohn Scipione opened. 2357192a931SJohn Scipione 2367192a931SJohn Scipione You can override this method in your BPopUpMenu derived class to return 2377192a931SJohn Scipione where the pop-up menu will appear on screen. 2387192a931SJohn Scipione 2397192a931SJohn Scipione \returns The location that the pop-up-menu will appear on screen in the 2407192a931SJohn Scipione screen's coordinate system. 2417192a931SJohn Scipione 242*47852bffSJohn Scipione \since BeOS R3 2437192a931SJohn Scipione*/ 244