feisty meow concerns codebase 2.140
menu_base.h
Go to the documentation of this file.
1//note: in progress.
2
3#ifndef MENU_BASE_CLASS
4#define MENU_BASE_CLASS
5
6/*****************************************************************************\
7* *
8* Name : menu_base *
9* Author : Chris Koeritz *
10* *
11*******************************************************************************
12* Copyright (c) 2003-$now By Author. This program is free software; you can *
13* redistribute it and/or modify it under the terms of the GNU General Public *
14* License as published by the Free Software Foundation; either version 2 of *
15* the License or (at your option) any later version. This is online at: *
16* http://www.fsf.org/copyleft/gpl.html *
17* Please send any updates to: fred@gruntose.com *
18\*****************************************************************************/
19
20
21
22#include <basis/contracts.h>
23
24// forward.
25class menu_common_amorph;
26
28
30
31class menu_common_base : public virtual root_object
32{
33public:
34 virtual ~menu_common_base();
35
36 bool enabled() const { return _enabled; }
37 void enable(bool enable = true) { _enabled = enable; }
38
39private:
40 bool _enabled;
41};
42
44
46
48: public menu_common_base
49{
50public:
51 menu_item(const string_array &triggers, const astring &text,
52 const astring &description);
54
57 menu_item(const menu_item &to_copy);
58
59 virtual ~menu_item();
60
61 menu_item &operator =(const menu_item &to_copy);
62
63 DEFINE_CLASS_NAME("menu_item");
64
65 const string_array &triggers() const;
66 const astring &text() const;
67 const astring &description() const;
68
69 virtual void menu_activation(char trigger);
71
73private:
74 string_array *_triggers;
75 astring *_text;
76 astring *_description;
77};
78
80
82
87{
88public:
89 menu_base(const astring &title, const menu_item &parameters);
90 //<! constructs a menu where the "title" is the name for this menu.
94 virtual ~menu_base();
95
96 DEFINE_CLASS_NAME("menu_base");
97
98 bool validate(bool recursive = true);
100
101 astring text_form() const;
103
105 astring recursive_text_form() const;
107
108 menu_common_base *evaluate_trigger(char trigger);
110
114 virtual void activate();
116
123 // note about the methods here: the menu_base takes over responsibility for
124 // pointers it is handed. do not delete the items after adding them or
125 // get an item and then delete it.
126 // also, the indices for menu items are separate from the indices for the
127 // sub-menus.
128
129 // menu item manipulators. the indexes here range from 0 to items() - 1.
130 int items() const;
131 void add_item(menu_item *to_invoke);
133 menu_item *get_item(int index);
135 bool zap_item(int index);
137 bool enable_item(int index, bool enable = true);
139
140 // submenu manipulation support. these range from 0 to submenus() - 1.
141 int submenus() const;
142 void add_submenu(menu_base *sub);
143 menu_base *get_submenu(int index);
145 bool zap_submenu(int index);
147 bool enable_submenu(int index, bool enable = true);
149
150private:
151 astring *_title;
152 menu_item *_parameters;
153 menu_common_amorph *_items;
154 menu_common_amorph *_menus;
155};
156
157#endif
158
A base class for a menu-driven interface model.
Definition menu_base.h:87
int submenus() const
number of submenus total.
bool enable_item(int index, bool enable=true)
enables or disabled the item at "index".
astring recursive_text_form() const
does a text_form on all menus and submenus rooted here.
bool zap_item(int index)
removes the item at "index" if possible.
menu_base * get_submenu(int index)
returns the submenu stored at "index".
bool validate(bool recursive=true)
checks that all of the menu_items
Definition menu_base.cpp:91
void add_submenu(menu_base *sub)
add a new submenu into "sub".
menu_item * get_item(int index)
gets the item at position "index". NULL_POINTER is returned if out of range.
bool zap_submenu(int index)
removes the submenu at the "index".
virtual ~menu_base()
Definition menu_base.cpp:84
menu_common_base * evaluate_trigger(char trigger)
returns the item or menu associated with the "trigger" value.
virtual void activate()
runs the menu structure by requesting input from the user.
DEFINE_CLASS_NAME("menu_base")
void add_item(menu_item *to_invoke)
adds a new menu_item onto this menu.
int items() const
returns the number of menu items stored.
bool enable_submenu(int index, bool enable=true)
enables or disables the submenu at the "index".
astring text_form() const
returns a string version of all the information here.
Definition menu_base.cpp:98
a common base class for referring to menu_items or menus polymorphically.
Definition menu_base.h:32
bool enabled() const
Definition menu_base.h:36
virtual ~menu_common_base()
Definition menu_base.cpp:29
void enable(bool enable=true)
Definition menu_base.h:37
A base class for the active items that can be stored inside a menu.
Definition menu_base.h:49
virtual ~menu_item()
Definition menu_base.cpp:48
const astring & text() const
Definition menu_base.cpp:67
const astring & description() const
Definition menu_base.cpp:69
DEFINE_CLASS_NAME("menu_item")
const string_array & triggers() const
Definition menu_base.cpp:65
menu_item & operator=(const menu_item &to_copy)
Definition menu_base.cpp:54
virtual void menu_activation(char trigger)
invoked when the user chooses the menu item in question.
Definition menu_base.cpp:63
string_array(1, math_list))) const char *addr_list[]