6 /*****************************************************************************\
9 * Author : Chris Koeritz *
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 \*****************************************************************************/
20 #include "menu_base.h"
22 #include <structures/string_array.h>
23 #include <structures/amorph.h>
25 class menu_common_amorph : public amorph<menu_common_base> {};
29 menu_common_base::~menu_common_base() {}
33 menu_item::menu_item(const string_array &trigs,
34 const astring &text, const astring &description)
35 : _triggers(new string_array(trigs)),
36 _text(new astring(text)),
37 _description(new astring(description))
40 menu_item::menu_item(const menu_item &to_copy)
43 _triggers(new string_array),
45 _description(new astring)
48 menu_item::~menu_item()
54 menu_item &menu_item::operator =(const menu_item &to_copy)
56 if (this == &to_copy) return *this;
57 *_triggers = *to_copy._triggers;
58 *_text = *to_copy._text;
59 *_description = *to_copy._description;
63 void menu_item::menu_activation(char formal(trigger)) {}
65 const string_array &menu_item::triggers() const { return *_triggers; }
67 const astring &menu_item::text() const { return *_text; }
69 const astring &menu_item::description() const { return *_description; }
73 //call this when menu invoked.
74 /// virtual bool menu_item_activity() = 0;
76 menu_base::menu_base(const astring &title, const menu_item ¶meters)
77 : _title(new astring(title)),
78 _parameters(new menu_item(parameters)),
79 _items(new menu_common_amorph),
80 _menus(new menu_common_amorph)
84 menu_base::~menu_base()
91 bool menu_base::validate(bool recursive)
94 //hmmm: implement this too....
98 astring menu_base::text_form() const
100 //hmmm: implement this too....
104 astring menu_base::recursive_text_form() const
106 //hmmm: implement this too....
110 int menu_base::items() const { return _items->elements(); }
112 void menu_base::add_item(menu_item *to_invoke)
114 if (!to_invoke) return;
115 *_items += to_invoke;
118 menu_item *menu_base::get_item(int index)
120 bounds_return(index, 0, _items->elements(), NULL_POINTER);
121 return dynamic_cast<menu_item *>(_items->borrow(index));
124 bool menu_base::zap_item(int index)
126 bounds_return(index, 0, _items->elements(), false);
127 _items->zap(index, index);
131 bool menu_base::enable_item(int index, bool enable)
133 bounds_return(index, 0, _items->elements(), false);
134 _items->borrow(index)->enable(enable);
138 int menu_base::submenus() const { return _menus->elements(); }
140 void menu_base::add_submenu(menu_base *sub)
146 menu_base *menu_base::get_submenu(int index)
148 bounds_return(index, 0, _menus->elements(), NULL_POINTER);
149 return dynamic_cast<menu_base *>(_menus->borrow(index));
152 bool menu_base::zap_submenu(int index)
154 bounds_return(index, 0, _menus->elements(), false);
155 _menus->zap(index, index);
159 bool menu_base::enable_submenu(int index, bool enable)
161 bounds_return(index, 0, _menus->elements(), false);
162 _menus->borrow(index)->enable(enable);
166 menu_common_base *menu_base::evaluate_trigger(char trigger)
168 //hmmm: implement this too....
173 void menu_base::activate()
175 //hmmm: implement this too....