1/* 2Open Tracker License 3 4Terms and Conditions 5 6Copyright (c) 1991-2001, Be Incorporated. All rights reserved. 7 8Permission is hereby granted, free of charge, to any person obtaining a copy of 9this software and associated documentation files (the "Software"), to deal in 10the Software without restriction, including without limitation the rights to 11use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12of the Software, and to permit persons to whom the Software is furnished to do 13so, subject to the following conditions: 14 15The above copyright notice and this permission notice applies to all licensees 16and shall be included in all copies or substantial portions of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN 23CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25Except as contained in this notice, the name of Be Incorporated shall not be 26used in advertising or otherwise to promote the sale, use or other dealings in 27this Software without prior written authorization from Be Incorporated. 28 29BeMail(TM), Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or 30registered trademarks of Be Incorporated in the United States and other 31countries. Other brand product names are registered trademarks or trademarks 32of their respective holders. All rights reserved. 33*/ 34 35 36#include "MailPopUpMenu.h" 37 38#include <Catalog.h> 39#include <Locale.h> 40#include <MenuItem.h> 41#include <Message.h> 42 43#include <malloc.h> 44#include <string.h> 45 46#include "MailSupport.h" 47#include "Messages.h" 48 49 50#define B_TRANSLATION_CONTEXT "Mail" 51 52 53TMenu::TMenu(const char *name, const char *attribute, int32 message, bool popup, 54 bool addRandom) 55 : BPopUpMenu(name, false, false), 56 fPopup(popup), 57 fAddRandom(addRandom), 58 fMessage(message) 59{ 60 fAttribute = strdup(attribute); 61 BuildMenu(); 62} 63 64 65TMenu::~TMenu() 66{ 67 free(fAttribute); 68} 69 70 71void 72TMenu::AttachedToWindow() 73{ 74 BuildMenu(); 75 BPopUpMenu::AttachedToWindow(); 76} 77 78 79BPoint 80TMenu::ScreenLocation(void) 81{ 82 if (fPopup) 83 return BPopUpMenu::ScreenLocation(); 84 85 return BMenu::ScreenLocation(); 86} 87 88 89void 90TMenu::BuildMenu() 91{ 92 RemoveItems(0, CountItems(), true); 93 add_query_menu_items(this, fAttribute, fMessage, NULL, fPopup); 94 95 if (fAddRandom && CountItems() > 0) { 96 AddItem(new BSeparatorItem(), 0); 97 98 BMessage *msg = new BMessage(M_RANDOM_SIG); 99 if (!fPopup) { 100 AddItem(new BMenuItem(B_TRANSLATE("Random"), msg, '0'), 0); 101 } else { 102 AddItem(new BMenuItem(B_TRANSLATE("Random"), msg), 0); 103 } 104 } 105} 106 107