1 /* 2 * Copyright 2006-2008, Haiku, Inc. 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 #include <Menu.h> 13 14 enum menu_states { 15 MENU_STATE_TRACKING = 0, 16 MENU_STATE_TRACKING_SUBMENU = 1, 17 MENU_STATE_CLOSED = 5 18 }; 19 20 21 class BBitmap; 22 class BMenu; 23 class BWindow; 24 25 namespace BPrivate { 26 27 extern const char *kEmptyMenuLabel; 28 29 class MenuPrivate { 30 public: 31 MenuPrivate(BMenu *menu); 32 33 menu_layout Layout() const; 34 35 void ItemMarked(BMenuItem *item); 36 void CacheFontInfo(); 37 38 float FontHeight() const; 39 float Ascent() const; 40 BRect Padding() const; 41 void GetItemMargins(float *, float *, float *, float *) const; 42 43 static bool IsAltCommandKey(); 44 45 int State(BMenuItem **item = NULL) const; 46 47 void Install(BWindow *window); 48 void Uninstall(); 49 void SetSuper(BMenu *menu); 50 void SetSuperItem(BMenuItem *item); 51 void InvokeItem(BMenuItem *item, bool now = false); 52 void QuitTracking(bool thisMenuOnly = true); 53 54 static status_t CreateBitmaps(); 55 static void DeleteBitmaps(); 56 57 static const BBitmap *MenuItemCommand(); 58 static const BBitmap *MenuItemControl(); 59 static const BBitmap *MenuItemOption(); 60 static const BBitmap *MenuItemShift(); 61 private: 62 BMenu *fMenu; 63 64 static BBitmap *sMenuItemAlt; 65 static BBitmap *sMenuItemControl; 66 static BBitmap *sMenuItemOption; 67 static BBitmap *sMenuItemShift; 68 69 }; 70 71 72 }; 73 74 75 // Note: since sqrt is slow, we don't use it and return the square of the distance 76 #define square(x) ((x) * (x)) 77 static inline float 78 point_distance(const BPoint &pointA, const BPoint &pointB) 79 { 80 return square(pointA.x - pointB.x) + square(pointA.y - pointB.y); 81 } 82 83 #undef square 84 85 86 #endif // __MENU_PRIVATE_H 87