17a8567e6SStefano Ceccherini /* 27a8567e6SStefano Ceccherini * Copyright 2001-2009, Haiku, Inc. 37a8567e6SStefano Ceccherini * Distributed under the terms of the MIT License. 47a8567e6SStefano Ceccherini * 57a8567e6SStefano Ceccherini * Authors: 67a8567e6SStefano Ceccherini * Stefano Ceccherini (stefano.ceccherini@gmail.com) 77a8567e6SStefano Ceccherini */ 87a8567e6SStefano Ceccherini 97a8567e6SStefano Ceccherini #include <MenuPrivate.h> 107a8567e6SStefano Ceccherini 117a8567e6SStefano Ceccherini #include <Bitmap.h> 127a8567e6SStefano Ceccherini #include <Menu.h> 137a8567e6SStefano Ceccherini 147a8567e6SStefano Ceccherini const unsigned char kCtrlBits[] = { 157a8567e6SStefano Ceccherini 0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x14, 167a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14, 177a8567e6SStefano Ceccherini 0x1d,0x1a,0x13,0x04,0x04,0x13,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14, 187a8567e6SStefano Ceccherini 0x1d,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x04,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x17,0x14, 197a8567e6SStefano Ceccherini 0x1d,0x1a,0x04,0x1a,0x1a,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x1a,0x1a,0x17,0x14, 207a8567e6SStefano Ceccherini 0x1d,0x1a,0x04,0x1a,0x1a,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x1a,0x1a,0x17,0x14, 217a8567e6SStefano Ceccherini 0x1d,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x1a,0x1a,0x17,0x14, 227a8567e6SStefano Ceccherini 0x1d,0x1a,0x13,0x04,0x04,0x13,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x04,0x04,0x1a,0x17,0x14, 237a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14, 247a8567e6SStefano Ceccherini 0x1d,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x14, 257a8567e6SStefano Ceccherini 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14 267a8567e6SStefano Ceccherini }; 277a8567e6SStefano Ceccherini 287a8567e6SStefano Ceccherini 297a8567e6SStefano Ceccherini const unsigned char kAltBits[] = { 307a8567e6SStefano Ceccherini 0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x14, 317a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14, 327a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x13,0x04,0x04,0x13,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14, 337a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x04,0x04,0x04,0x1a,0x17,0x14, 347a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14, 357a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x04,0x04,0x04,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14, 367a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14, 377a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x04,0x04,0x1a,0x04,0x1a,0x1a,0x17,0x14, 387a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14, 397a8567e6SStefano Ceccherini 0x1d,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x14, 407a8567e6SStefano Ceccherini 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14 417a8567e6SStefano Ceccherini }; 427a8567e6SStefano Ceccherini 437a8567e6SStefano Ceccherini 447a8567e6SStefano Ceccherini const unsigned char kOptBits[] = { 457a8567e6SStefano Ceccherini 0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x14, 467a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14, 477a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x13,0x04,0x04,0x13,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14, 487a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x04,0x1a,0x04,0x04,0x04,0x1a,0x17,0x14, 497a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x17,0x14, 507a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x04,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14, 517a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x04,0x1a,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14, 527a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x13,0x04,0x04,0x13,0x1a,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14, 537a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14, 547a8567e6SStefano Ceccherini 0x1d,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x14, 557a8567e6SStefano Ceccherini 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14 567a8567e6SStefano Ceccherini }; 577a8567e6SStefano Ceccherini 587a8567e6SStefano Ceccherini 597a8567e6SStefano Ceccherini const unsigned char kShiftBits[] = { 607a8567e6SStefano Ceccherini 0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x14, 617a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14, 627a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x17,0x04,0x04,0x17,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14, 637a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x04,0x17,0x17,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x04,0x04,0x1a,0x04,0x04,0x04,0x1a,0x17,0x14, 647a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x17,0x04,0x04,0x17,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14, 657a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x04,0x1a,0x04,0x04,0x04,0x1a,0x04,0x04,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14, 667a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x04,0x17,0x17,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14, 677a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x17,0x04,0x04,0x17,0x1a,0x04,0x1a,0x04,0x1a,0x04,0x1a,0x1a,0x1a,0x1a,0x04,0x1a,0x1a,0x17,0x14, 687a8567e6SStefano Ceccherini 0x1d,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x17,0x14, 697a8567e6SStefano Ceccherini 0x1d,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x14, 707a8567e6SStefano Ceccherini 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14 717a8567e6SStefano Ceccherini }; 727a8567e6SStefano Ceccherini 737a8567e6SStefano Ceccherini namespace BPrivate { 747a8567e6SStefano Ceccherini 757a8567e6SStefano Ceccherini BBitmap *gMenuItemAlt; 767a8567e6SStefano Ceccherini BBitmap *gMenuItemControl; 777a8567e6SStefano Ceccherini BBitmap *gMenuItemOption; 787a8567e6SStefano Ceccherini BBitmap *gMenuItemShift; 797a8567e6SStefano Ceccherini 807a8567e6SStefano Ceccherini MenuPrivate::MenuPrivate(BMenu *menu) 817a8567e6SStefano Ceccherini : 827a8567e6SStefano Ceccherini fMenu(menu) 837a8567e6SStefano Ceccherini { 847a8567e6SStefano Ceccherini } 857a8567e6SStefano Ceccherini 867a8567e6SStefano Ceccherini 877a8567e6SStefano Ceccherini menu_layout 887a8567e6SStefano Ceccherini MenuPrivate::Layout() const 897a8567e6SStefano Ceccherini { 907a8567e6SStefano Ceccherini return fMenu->Layout(); 917a8567e6SStefano Ceccherini } 927a8567e6SStefano Ceccherini 937a8567e6SStefano Ceccherini 947a8567e6SStefano Ceccherini void 957a8567e6SStefano Ceccherini MenuPrivate::ItemMarked(BMenuItem *item) 967a8567e6SStefano Ceccherini { 977a8567e6SStefano Ceccherini fMenu->_ItemMarked(item); 987a8567e6SStefano Ceccherini } 997a8567e6SStefano Ceccherini 1007a8567e6SStefano Ceccherini 1017a8567e6SStefano Ceccherini void 1027a8567e6SStefano Ceccherini MenuPrivate::CacheFontInfo() 1037a8567e6SStefano Ceccherini { 1047a8567e6SStefano Ceccherini fMenu->_CacheFontInfo(); 1057a8567e6SStefano Ceccherini } 1067a8567e6SStefano Ceccherini 1077a8567e6SStefano Ceccherini 1087a8567e6SStefano Ceccherini float 1097a8567e6SStefano Ceccherini MenuPrivate::FontHeight() const 1107a8567e6SStefano Ceccherini { 1117a8567e6SStefano Ceccherini return fMenu->fFontHeight; 1127a8567e6SStefano Ceccherini } 1137a8567e6SStefano Ceccherini 1147a8567e6SStefano Ceccherini 1157a8567e6SStefano Ceccherini float 1167a8567e6SStefano Ceccherini MenuPrivate::Ascent() const 1177a8567e6SStefano Ceccherini { 1187a8567e6SStefano Ceccherini return fMenu->fAscent; 1197a8567e6SStefano Ceccherini } 1207a8567e6SStefano Ceccherini 1217a8567e6SStefano Ceccherini 1227a8567e6SStefano Ceccherini BRect 1237a8567e6SStefano Ceccherini MenuPrivate::Padding() const 1247a8567e6SStefano Ceccherini { 1257a8567e6SStefano Ceccherini return fMenu->fPad; 1267a8567e6SStefano Ceccherini } 1277a8567e6SStefano Ceccherini 1287a8567e6SStefano Ceccherini 1297a8567e6SStefano Ceccherini void 1307a8567e6SStefano Ceccherini MenuPrivate::GetItemMargins(float *left, float *top, 1317a8567e6SStefano Ceccherini float *right, float *bottom) const 1327a8567e6SStefano Ceccherini { 1337a8567e6SStefano Ceccherini fMenu->GetItemMargins(left, top, right, bottom); 1347a8567e6SStefano Ceccherini } 1357a8567e6SStefano Ceccherini 1367a8567e6SStefano Ceccherini 1377a8567e6SStefano Ceccherini bool 1387a8567e6SStefano Ceccherini MenuPrivate::IsAltCommandKey() const 1397a8567e6SStefano Ceccherini { 1407a8567e6SStefano Ceccherini return fMenu->sAltAsCommandKey; 1417a8567e6SStefano Ceccherini } 1427a8567e6SStefano Ceccherini 1437a8567e6SStefano Ceccherini 1447a8567e6SStefano Ceccherini int 1457a8567e6SStefano Ceccherini MenuPrivate::State(BMenuItem **item) const 1467a8567e6SStefano Ceccherini { 1477a8567e6SStefano Ceccherini return fMenu->_State(item); 1487a8567e6SStefano Ceccherini } 1497a8567e6SStefano Ceccherini 1507a8567e6SStefano Ceccherini 1517a8567e6SStefano Ceccherini void 1527a8567e6SStefano Ceccherini MenuPrivate::Install(BWindow *window) 1537a8567e6SStefano Ceccherini { 1547a8567e6SStefano Ceccherini fMenu->_Install(window); 1557a8567e6SStefano Ceccherini } 1567a8567e6SStefano Ceccherini 1577a8567e6SStefano Ceccherini 1587a8567e6SStefano Ceccherini void 1597a8567e6SStefano Ceccherini MenuPrivate::Uninstall() 1607a8567e6SStefano Ceccherini { 1617a8567e6SStefano Ceccherini fMenu->_Uninstall(); 1627a8567e6SStefano Ceccherini } 1637a8567e6SStefano Ceccherini 1647a8567e6SStefano Ceccherini 1657a8567e6SStefano Ceccherini void 1667a8567e6SStefano Ceccherini MenuPrivate::SetSuper(BMenu *menu) 1677a8567e6SStefano Ceccherini { 1687a8567e6SStefano Ceccherini fMenu->fSuper = menu; 1697a8567e6SStefano Ceccherini } 1707a8567e6SStefano Ceccherini 1717a8567e6SStefano Ceccherini 1727a8567e6SStefano Ceccherini void 1737a8567e6SStefano Ceccherini MenuPrivate::SetSuperItem(BMenuItem *item) 1747a8567e6SStefano Ceccherini { 1757a8567e6SStefano Ceccherini fMenu->fSuperitem = item; 1767a8567e6SStefano Ceccherini } 1777a8567e6SStefano Ceccherini 1787a8567e6SStefano Ceccherini 1797a8567e6SStefano Ceccherini void 1807a8567e6SStefano Ceccherini MenuPrivate::InvokeItem(BMenuItem *item, bool now) 1817a8567e6SStefano Ceccherini { 1827a8567e6SStefano Ceccherini fMenu->_InvokeItem(item, now); 1837a8567e6SStefano Ceccherini } 1847a8567e6SStefano Ceccherini 1857a8567e6SStefano Ceccherini 1867a8567e6SStefano Ceccherini void 1877a8567e6SStefano Ceccherini MenuPrivate::QuitTracking(bool thisMenuOnly) 1887a8567e6SStefano Ceccherini { 1897a8567e6SStefano Ceccherini fMenu->_QuitTracking(thisMenuOnly); 1907a8567e6SStefano Ceccherini } 1917a8567e6SStefano Ceccherini 1927a8567e6SStefano Ceccherini 1937a8567e6SStefano Ceccherini /* static */ 1947a8567e6SStefano Ceccherini status_t 1957a8567e6SStefano Ceccherini MenuPrivate::CreateBitmaps() 1967a8567e6SStefano Ceccherini { 1977a8567e6SStefano Ceccherini BRect smallRect(0, 0, 16, 10); 1987a8567e6SStefano Ceccherini BRect largeRect(0, 0, 21, 10); 199*eac9c545SStefano Ceccherini try { 2007a8567e6SStefano Ceccherini gMenuItemAlt = new BBitmap(smallRect, B_CMAP8); 2017a8567e6SStefano Ceccherini gMenuItemControl = new BBitmap(smallRect, B_CMAP8); 2027a8567e6SStefano Ceccherini gMenuItemOption = new BBitmap(smallRect, B_CMAP8); 2037a8567e6SStefano Ceccherini gMenuItemShift = new BBitmap(largeRect, B_CMAP8); 204*eac9c545SStefano Ceccherini } catch (...) { 205*eac9c545SStefano Ceccherini return B_NO_MEMORY; 206*eac9c545SStefano Ceccherini } 2077a8567e6SStefano Ceccherini 2087a8567e6SStefano Ceccherini gMenuItemAlt->ImportBits(kAltBits, sizeof(kAltBits), 2097a8567e6SStefano Ceccherini 17, 0, B_CMAP8); 2107a8567e6SStefano Ceccherini gMenuItemControl->ImportBits(kCtrlBits, sizeof(kCtrlBits), 2117a8567e6SStefano Ceccherini 17, 0, B_CMAP8); 2127a8567e6SStefano Ceccherini gMenuItemOption->ImportBits(kOptBits, sizeof(kOptBits), 2137a8567e6SStefano Ceccherini 17, 0, B_CMAP8); 2147a8567e6SStefano Ceccherini gMenuItemShift->ImportBits(kShiftBits, sizeof(kShiftBits), 2157a8567e6SStefano Ceccherini 22, 0, B_CMAP8); 2167a8567e6SStefano Ceccherini 2177a8567e6SStefano Ceccherini return B_OK; 2187a8567e6SStefano Ceccherini } 2197a8567e6SStefano Ceccherini 2207a8567e6SStefano Ceccherini 2217a8567e6SStefano Ceccherini /* static */ 2227a8567e6SStefano Ceccherini void 2237a8567e6SStefano Ceccherini MenuPrivate::DeleteBitmaps() 2247a8567e6SStefano Ceccherini { 2257a8567e6SStefano Ceccherini delete gMenuItemAlt; 2267a8567e6SStefano Ceccherini delete gMenuItemControl; 2277a8567e6SStefano Ceccherini delete gMenuItemOption; 2287a8567e6SStefano Ceccherini delete gMenuItemShift; 2297a8567e6SStefano Ceccherini } 2307a8567e6SStefano Ceccherini 2317a8567e6SStefano Ceccherini 2327a8567e6SStefano Ceccherini /* static */ 2337a8567e6SStefano Ceccherini const BBitmap * 2347a8567e6SStefano Ceccherini MenuPrivate::MenuItemCommand() 2357a8567e6SStefano Ceccherini { 2367a8567e6SStefano Ceccherini if (BMenu::sAltAsCommandKey) 2377a8567e6SStefano Ceccherini return gMenuItemAlt; 2387a8567e6SStefano Ceccherini 2397a8567e6SStefano Ceccherini return gMenuItemControl; 2407a8567e6SStefano Ceccherini } 2417a8567e6SStefano Ceccherini 2427a8567e6SStefano Ceccherini 2437a8567e6SStefano Ceccherini /* static */ 2447a8567e6SStefano Ceccherini const BBitmap * 2457a8567e6SStefano Ceccherini MenuPrivate::MenuItemControl() 2467a8567e6SStefano Ceccherini { 2477a8567e6SStefano Ceccherini if (BMenu::sAltAsCommandKey) 2487a8567e6SStefano Ceccherini return gMenuItemControl; 2497a8567e6SStefano Ceccherini 2507a8567e6SStefano Ceccherini return gMenuItemAlt; 2517a8567e6SStefano Ceccherini } 2527a8567e6SStefano Ceccherini 2537a8567e6SStefano Ceccherini 2547a8567e6SStefano Ceccherini /* static */ 2557a8567e6SStefano Ceccherini const BBitmap * 2567a8567e6SStefano Ceccherini MenuPrivate::MenuItemOption() 2577a8567e6SStefano Ceccherini { 2587a8567e6SStefano Ceccherini return gMenuItemOption; 2597a8567e6SStefano Ceccherini } 2607a8567e6SStefano Ceccherini 2617a8567e6SStefano Ceccherini 2627a8567e6SStefano Ceccherini /* static */ 2637a8567e6SStefano Ceccherini const BBitmap * 2647a8567e6SStefano Ceccherini MenuPrivate::MenuItemShift() 2657a8567e6SStefano Ceccherini { 2667a8567e6SStefano Ceccherini return gMenuItemShift; 2677a8567e6SStefano Ceccherini } 2687a8567e6SStefano Ceccherini 2697a8567e6SStefano Ceccherini 2707a8567e6SStefano Ceccherini } // namespace BPrivate 271