1 /* 2 * Copyright 2006-2015 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stefano Ceccherini (stefano.ceccherini@gmail.com) 7 */ 8 9 #ifndef __MENU_PRIVATE_H 10 #define __MENU_PRIVATE_H 11 12 13 #include <Menu.h> 14 15 16 enum menu_states { 17 MENU_STATE_TRACKING = 0, 18 MENU_STATE_TRACKING_SUBMENU = 1, 19 MENU_STATE_KEY_TO_SUBMENU = 2, 20 MENU_STATE_KEY_LEAVE_SUBMENU = 3, 21 MENU_STATE_CLOSED = 5 22 }; 23 24 25 class BBitmap; 26 class BMenu; 27 class BWindow; 28 29 30 namespace BPrivate { 31 32 extern const char* kEmptyMenuLabel; 33 34 class MenuPrivate { 35 public: 36 MenuPrivate(BMenu* menu); 37 38 menu_layout Layout() const; 39 void SetLayout(menu_layout layout); 40 41 void ItemMarked(BMenuItem* item); 42 void CacheFontInfo(); 43 44 float FontHeight() const; 45 float Ascent() const; 46 BRect Padding() const; 47 void GetItemMargins(float*, float*, float*, float*) 48 const; 49 void SetItemMargins(float, float, float, float); 50 51 int State(BMenuItem** item = NULL) const; 52 53 void Install(BWindow* window); 54 void Uninstall(); 55 void SetSuper(BMenu* menu); 56 void SetSuperItem(BMenuItem* item); 57 void InvokeItem(BMenuItem* item, bool now = false); 58 void QuitTracking(bool thisMenuOnly = true); 59 bool HasSubmenus() { return fMenu->fHasSubmenus; } 60 61 static status_t CreateBitmaps(); 62 static void DeleteBitmaps(); 63 64 static const BBitmap* MenuItemShift(); 65 static const BBitmap* MenuItemControl(); 66 static const BBitmap* MenuItemOption(); 67 static const BBitmap* MenuItemCommand(); 68 static const BBitmap* MenuItemMenu(); 69 70 private: 71 BMenu* fMenu; 72 73 static BBitmap* sMenuItemShift; 74 static BBitmap* sMenuItemControl; 75 static BBitmap* sMenuItemOption; 76 static BBitmap* sMenuItemAlt; 77 static BBitmap* sMenuItemMenu; 78 79 }; 80 81 }; // namespace BPrivate 82 83 84 // Note: since sqrt is slow, we don't use it and return the square of the 85 // distance 86 #define square(x) ((x) * (x)) 87 static inline float 88 point_distance(const BPoint &pointA, const BPoint &pointB) 89 { 90 return square(pointA.x - pointB.x) + square(pointA.y - pointB.y); 91 } 92 #undef square 93 94 95 #endif // __MENU_PRIVATE_H 96