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 50 int State(BMenuItem** item = NULL) const; 51 52 void Install(BWindow* window); 53 void Uninstall(); 54 void SetSuper(BMenu* menu); 55 void SetSuperItem(BMenuItem* item); 56 void InvokeItem(BMenuItem* item, bool now = false); 57 void QuitTracking(bool thisMenuOnly = true); 58 59 static status_t CreateBitmaps(); 60 static void DeleteBitmaps(); 61 62 static const BBitmap* MenuItemShift(); 63 static const BBitmap* MenuItemControl(); 64 static const BBitmap* MenuItemOption(); 65 static const BBitmap* MenuItemCommand(); 66 static const BBitmap* MenuItemMenu(); 67 68 private: 69 BMenu* fMenu; 70 71 static BBitmap* sMenuItemShift; 72 static BBitmap* sMenuItemControl; 73 static BBitmap* sMenuItemOption; 74 static BBitmap* sMenuItemAlt; 75 static BBitmap* sMenuItemMenu; 76 77 }; 78 79 }; // namespace BPrivate 80 81 82 // Note: since sqrt is slow, we don't use it and return the square of the 83 // distance 84 #define square(x) ((x) * (x)) 85 static inline float 86 point_distance(const BPoint &pointA, const BPoint &pointB) 87 { 88 return square(pointA.x - pointB.x) + square(pointA.y - pointB.y); 89 } 90 #undef square 91 92 93 #endif // __MENU_PRIVATE_H 94