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.
25
class
menu_common_amorph;
26
28
30
31
class
menu_common_base
:
public
virtual
root_object
32
{
33
public
:
34
virtual
~menu_common_base
();
35
36
bool
enabled
()
const
{
return
_enabled; }
37
void
enable
(
bool
enable
=
true
) { _enabled =
enable
; }
38
39
private
:
40
bool
_enabled;
41
};
42
44
46
47
class
menu_item
48
:
public
menu_common_base
49
{
50
public
:
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
73
private
:
74
string_array
*_triggers;
75
astring *_text;
76
astring *_description;
77
};
78
80
82
86
class
menu_base
:
public
menu_common_base
87
{
88
public
:
89
menu_base
(
const
astring &title,
const
menu_item
¶meters);
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
150
private
:
151
astring *_title;
152
menu_item
*_parameters;
153
menu_common_amorph *_items;
154
menu_common_amorph *_menus;
155
};
156
157
#endif
158
menu_base
A base class for a menu-driven interface model.
Definition:
menu_base.h:87
menu_base::submenus
int submenus() const
number of submenus total.
Definition:
menu_base.cpp:138
menu_base::enable_item
bool enable_item(int index, bool enable=true)
enables or disabled the item at "index".
Definition:
menu_base.cpp:131
menu_base::recursive_text_form
astring recursive_text_form() const
does a text_form on all menus and submenus rooted here.
Definition:
menu_base.cpp:104
menu_base::zap_item
bool zap_item(int index)
removes the item at "index" if possible.
Definition:
menu_base.cpp:124
menu_base::get_submenu
menu_base * get_submenu(int index)
returns the submenu stored at "index".
Definition:
menu_base.cpp:146
menu_base::validate
bool validate(bool recursive=true)
checks that all of the menu_items
Definition:
menu_base.cpp:91
menu_base::add_submenu
void add_submenu(menu_base *sub)
add a new submenu into "sub".
Definition:
menu_base.cpp:140
menu_base::get_item
menu_item * get_item(int index)
gets the item at position "index". NULL_POINTER is returned if out of range.
Definition:
menu_base.cpp:118
menu_base::zap_submenu
bool zap_submenu(int index)
removes the submenu at the "index".
Definition:
menu_base.cpp:152
menu_base::menu_base
menu_base(const astring &title, const menu_item ¶meters)
virtual bool menu_item_activity() = 0;
Definition:
menu_base.cpp:76
menu_base::~menu_base
virtual ~menu_base()
Definition:
menu_base.cpp:84
menu_base::evaluate_trigger
menu_common_base * evaluate_trigger(char trigger)
returns the item or menu associated with the "trigger" value.
Definition:
menu_base.cpp:166
menu_base::activate
virtual void activate()
runs the menu structure by requesting input from the user.
Definition:
menu_base.cpp:173
menu_base::DEFINE_CLASS_NAME
DEFINE_CLASS_NAME("menu_base")
menu_base::add_item
void add_item(menu_item *to_invoke)
adds a new menu_item onto this menu.
Definition:
menu_base.cpp:112
menu_base::items
int items() const
returns the number of menu items stored.
Definition:
menu_base.cpp:110
menu_base::enable_submenu
bool enable_submenu(int index, bool enable=true)
enables or disables the submenu at the "index".
Definition:
menu_base.cpp:159
menu_base::text_form
astring text_form() const
returns a string version of all the information here.
Definition:
menu_base.cpp:98
menu_common_base
a common base class for referring to menu_items or menus polymorphically.
Definition:
menu_base.h:32
menu_common_base::enabled
bool enabled() const
Definition:
menu_base.h:36
menu_common_base::~menu_common_base
virtual ~menu_common_base()
Definition:
menu_base.cpp:29
menu_common_base::enable
void enable(bool enable=true)
Definition:
menu_base.h:37
menu_item
A base class for the active items that can be stored inside a menu.
Definition:
menu_base.h:49
menu_item::~menu_item
virtual ~menu_item()
Definition:
menu_base.cpp:48
menu_item::text
const astring & text() const
Definition:
menu_base.cpp:67
menu_item::description
const astring & description() const
Definition:
menu_base.cpp:69
menu_item::DEFINE_CLASS_NAME
DEFINE_CLASS_NAME("menu_item")
menu_item::triggers
const string_array & triggers() const
Definition:
menu_base.cpp:65
menu_item::operator=
menu_item & operator=(const menu_item &to_copy)
Definition:
menu_base.cpp:54
menu_item::menu_activation
virtual void menu_activation(char trigger)
invoked when the user chooses the menu item in question.
Definition:
menu_base.cpp:63
menu_item::menu_item
menu_item(const string_array &triggers, const astring &text, const astring &description)
constructs a menu item that shows the "text" and "description".
Definition:
menu_base.cpp:33
contracts.h
string_array
string_array(1, math_list))) const char *addr_list[]
graphiq
library
user_interface
menu_base.h
Generated by
1.9.1