1 /* 2 * Copyright 2004-2010, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef KERNEL_BOOT_MENU_H 6 #define KERNEL_BOOT_MENU_H 7 8 9 #include <SupportDefs.h> 10 #include <util/DoublyLinkedList.h> 11 12 13 class Menu; 14 class MenuItem; 15 16 typedef bool (*menu_item_hook)(Menu* menu, MenuItem* item); 17 typedef void (*shortcut_hook)(char key); 18 19 20 enum menu_item_type { 21 MENU_ITEM_STANDARD = 1, 22 MENU_ITEM_MARKABLE, 23 MENU_ITEM_TITLE, 24 MENU_ITEM_NO_CHOICE, 25 MENU_ITEM_SEPARATOR, 26 }; 27 28 29 class MenuItem : public DoublyLinkedListLinkImpl<MenuItem> { 30 public: 31 MenuItem(const char* label = NULL, 32 Menu* subMenu = NULL); 33 virtual ~MenuItem(); 34 35 void SetTarget(menu_item_hook target); Target()36 menu_item_hook Target() const { return fTarget; } 37 38 virtual void SetMarked(bool marked); IsMarked()39 bool IsMarked() const { return fIsMarked; } 40 41 void Select(bool selected); IsSelected()42 bool IsSelected() const { return fIsSelected; } 43 44 void SetEnabled(bool enabled); IsEnabled()45 bool IsEnabled() const { return fIsEnabled; } 46 47 void SetType(menu_item_type type); Type()48 menu_item_type Type() const { return fType; } 49 50 void SetData(const void* data); Data()51 const void* Data() const { return fData; } 52 53 void SetHelpText(const char* text); HelpText()54 const char* HelpText() const { return fHelpText; } 55 56 void SetShortcut(char key); Shortcut()57 char Shortcut() const { return fShortcut; } 58 Label()59 const char* Label() const { return fLabel; } 60 void SetLabel(const char* label); 61 Submenu()62 Menu* Submenu() const { return fSubMenu; } 63 void SetSubmenu(Menu* subMenu); 64 Supermenu()65 Menu* Supermenu() const { return fMenu; } 66 67 private: 68 friend class Menu; 69 void SetMenu(Menu* menu); 70 71 private: 72 const char* fLabel; 73 menu_item_hook fTarget; 74 bool fIsMarked; 75 bool fIsSelected; 76 bool fIsEnabled; 77 menu_item_type fType; 78 Menu* fMenu; 79 Menu* fSubMenu; 80 const void* fData; 81 const char* fHelpText; 82 char fShortcut; 83 }; 84 85 86 typedef DoublyLinkedList<MenuItem> MenuItemList; 87 typedef MenuItemList::Iterator MenuItemIterator; 88 89 90 enum menu_type { 91 MAIN_MENU = 1, 92 SAFE_MODE_MENU, 93 STANDARD_MENU, 94 CHOICE_MENU, 95 }; 96 97 98 class Menu { 99 public: 100 Menu(menu_type type, const char* title = NULL); 101 virtual ~Menu(); 102 Type()103 menu_type Type() const { return fType; } 104 105 virtual void Entered(); 106 virtual void Exited(); 107 Hide()108 void Hide() { fIsHidden = true; } Show()109 void Show() { fIsHidden = false; } IsHidden()110 bool IsHidden() const { return fIsHidden; } 111 ItemIterator()112 MenuItemIterator ItemIterator() { return fItems.GetIterator(); } 113 MenuItem* ItemAt(int32 index); 114 int32 IndexOf(MenuItem* item); 115 int32 CountItems() const; 116 117 MenuItem* FindItem(const char* label); 118 MenuItem* FindMarked(); 119 MenuItem* FindSelected(int32* _index = NULL); 120 121 void AddItem(MenuItem* item); 122 status_t AddSeparatorItem(); 123 124 MenuItem* RemoveItemAt(int32 index); 125 void RemoveItem(MenuItem* item); 126 Superitem()127 MenuItem* Superitem() const { return fSuperItem; } Supermenu()128 Menu* Supermenu() const 129 { return fSuperItem 130 ? fSuperItem->fMenu : NULL; } 131 Title()132 const char* Title() const { return fTitle; } SetTitle(const char * title)133 void SetTitle(const char* title) 134 { fTitle = title; } 135 SetChoiceText(const char * text)136 void SetChoiceText(const char* text) 137 { fChoiceText = text; } ChoiceText()138 const char* ChoiceText() const { return fChoiceText; } 139 140 void AddShortcut(char key, shortcut_hook function); 141 shortcut_hook FindShortcut(char key) const; 142 MenuItem* FindItemByShortcut(char key); 143 144 void SortItems(bool (*less)(const MenuItem*, 145 const MenuItem*)); 146 147 void Run(); 148 149 private: 150 friend class MenuItem; 151 void Draw(MenuItem* item); 152 153 private: 154 struct shortcut { 155 shortcut* next; 156 shortcut_hook function; 157 char key; 158 }; 159 160 const char* fTitle; 161 const char* fChoiceText; 162 int32 fCount; 163 bool fIsHidden; 164 MenuItemList fItems; 165 menu_type fType; 166 MenuItem* fSuperItem; 167 shortcut* fShortcuts; 168 }; 169 170 171 #endif /* KERNEL_BOOT_MENU_H */ 172