1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef SETTINGS_MENU_H 6 #define SETTINGS_MENU_H 7 8 9 #include <MenuItem.h> 10 11 #include <Referenceable.h> 12 13 #include "Settings.h" 14 15 16 class BoolSetting; 17 class OptionsSetting; 18 19 20 class SettingsMenu : public BReferenceable { 21 public: 22 SettingsMenu(); 23 virtual ~SettingsMenu(); 24 25 virtual status_t AddToMenu(BMenu* menu, int32 index) = 0; 26 virtual void RemoveFromMenu() = 0; 27 28 virtual void PrepareToShow(BLooper* parentLooper) = 0; 29 virtual bool Finish(BLooper* parentLooper, bool force) = 0; 30 }; 31 32 33 class SettingMenuItem : public BMenuItem { 34 public: 35 SettingMenuItem(Setting* setting, 36 const char* label, BMessage* message, 37 char shortcut = 0, uint32 modifiers = 0); 38 SettingMenuItem(Setting* setting, BMenu* menu, 39 BMessage* message = NULL); 40 virtual ~SettingMenuItem(); 41 42 Setting* GetSetting() const { return fSetting; } 43 44 virtual void PrepareToShow(BLooper* parentLooper, 45 BHandler* targetHandler, 46 Settings* settings); 47 virtual bool Finish(BLooper* parentLooper, 48 BHandler* targetHandler, bool force); 49 50 virtual void ItemSelected(Settings* settings); 51 52 protected: 53 Setting* fSetting; 54 }; 55 56 57 class SettingsMenuImpl : public SettingsMenu, private BHandler { 58 public: 59 SettingsMenuImpl(Settings* settings); 60 virtual ~SettingsMenuImpl(); 61 62 bool AddItem(SettingMenuItem* item); 63 // takes over ownership 64 bool AddBoolItem(BoolSetting* setting); 65 bool AddOptionsItem(OptionsSetting* setting); 66 67 BMenu* Menu() const { return fMenu; } 68 virtual status_t AddToMenu(BMenu* menu, int32 index); 69 virtual void RemoveFromMenu(); 70 71 virtual void PrepareToShow(BLooper* parentLooper); 72 virtual bool Finish(BLooper* parentLooper, bool force); 73 74 Settings* GetSettings() const { return fSettings; } 75 76 private: 77 virtual void MessageReceived(BMessage* message); 78 79 private: 80 class MenuItem; 81 class BoolMenuItem; 82 class OptionMenuItem; 83 class OptionsMenuItem; 84 85 typedef BObjectList<SettingMenuItem> MenuItemList; 86 87 private: 88 SettingMenuItem* _FindMenuItem(Setting* setting) const; 89 90 private: 91 Settings* fSettings; 92 BMenu* fMenu; 93 MenuItemList fMenuItems; 94 }; 95 96 97 #endif // SETTINGS_MENU_H 98