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