1 /* 2 * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 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 *, MenuItem *); 17 18 enum menu_item_type { 19 MENU_ITEM_STANDARD = 1, 20 MENU_ITEM_MARKABLE, 21 MENU_ITEM_TITLE, 22 MENU_ITEM_NO_CHOICE, 23 MENU_ITEM_SEPARATOR, 24 }; 25 26 class MenuItem : public DoublyLinkedListLinkImpl<MenuItem> { 27 public: 28 MenuItem(const char *label = NULL, Menu *subMenu = NULL); 29 ~MenuItem(); 30 31 void SetTarget(menu_item_hook target); 32 menu_item_hook Target() const { return fTarget; } 33 34 void SetMarked(bool marked); 35 bool IsMarked() const { return fIsMarked; } 36 37 void Select(bool selected); 38 bool IsSelected() const { return fIsSelected; } 39 40 void SetEnabled(bool enabled); 41 bool IsEnabled() const { return fIsEnabled; } 42 43 void SetType(menu_item_type type); 44 menu_item_type Type() const { return fType; } 45 46 void SetData(const void *data); 47 const void *Data() const { return fData; } 48 49 void SetHelpText(const char *text); 50 const char *HelpText() const { return fHelpText; } 51 52 const char *Label() const { return fLabel; } 53 Menu *Submenu() const { return fSubMenu; } 54 55 private: 56 friend class Menu; 57 void SetMenu(Menu *menu); 58 59 const char *fLabel; 60 menu_item_hook fTarget; 61 bool fIsMarked; 62 bool fIsSelected; 63 bool fIsEnabled; 64 menu_item_type fType; 65 Menu *fMenu, *fSubMenu; 66 const void *fData; 67 const char *fHelpText; 68 }; 69 70 typedef DoublyLinkedList<MenuItem> MenuItemList; 71 typedef MenuItemList::Iterator MenuItemIterator; 72 73 enum menu_type { 74 MAIN_MENU = 1, 75 SAFE_MODE_MENU, 76 STANDARD_MENU, 77 CHOICE_MENU, 78 }; 79 80 class Menu { 81 public: 82 Menu(menu_type type, const char *title = NULL); 83 ~Menu(); 84 85 menu_type Type() const { return fType; } 86 87 void Hide() { fIsHidden = true; } 88 void Show() { fIsHidden = false; } 89 bool IsHidden() const { return fIsHidden; } 90 91 MenuItemIterator ItemIterator() { return fItems.GetIterator(); } 92 MenuItem *ItemAt(int32 index); 93 int32 IndexOf(MenuItem *item); 94 int32 CountItems() const; 95 96 MenuItem *FindItem(const char *label); 97 MenuItem *FindMarked(); 98 MenuItem *FindSelected(int32 *_index = NULL); 99 100 void AddItem(MenuItem *item); 101 status_t AddSeparatorItem(); 102 103 MenuItem *RemoveItemAt(int32 index); 104 void RemoveItem(MenuItem *item); 105 106 MenuItem *Superitem() const { return fSuperItem; } 107 Menu *Supermenu() const { return fSuperItem ? fSuperItem->fMenu : NULL; } 108 109 const char *Title() const { return fTitle; } 110 111 void SetChoiceText(const char *text) { fChoiceText = text; } 112 const char *ChoiceText() const { return fChoiceText; } 113 114 void Run(); 115 116 private: 117 friend class MenuItem; 118 void Draw(MenuItem *item); 119 120 const char *fTitle; 121 const char *fChoiceText; 122 int32 fCount; 123 bool fIsHidden; 124 MenuItemList fItems; 125 menu_type fType; 126 MenuItem *fSuperItem; 127 }; 128 129 #endif /* KERNEL_BOOT_MENU_H */ 130