menu_base.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "menu_base.h"
00021
00022 #include <structures/string_array.h>
00023 #include <structures/amorph.h>
00024
00025 class menu_common_amorph : public amorph<menu_common_base> {};
00026
00028
00029 menu_common_base::~menu_common_base() {}
00030
00032
00033 menu_item::menu_item(const string_array &trigs,
00034 const astring &text, const astring &description)
00035 : _triggers(new string_array(trigs)),
00036 _text(new astring(text)),
00037 _description(new astring(description))
00038 {}
00039
00040 menu_item::menu_item(const menu_item &to_copy)
00041 : root_object(),
00042 menu_common_base(),
00043 _triggers(new string_array),
00044 _text(new astring),
00045 _description(new astring)
00046 { *this = to_copy; }
00047
00048 menu_item::~menu_item()
00049 {
00050 WHACK(_text);
00051 WHACK(_description);
00052 }
00053
00054 menu_item &menu_item::operator =(const menu_item &to_copy)
00055 {
00056 if (this == &to_copy) return *this;
00057 *_triggers = *to_copy._triggers;
00058 *_text = *to_copy._text;
00059 *_description = *to_copy._description;
00060 return *this;
00061 }
00062
00063 void menu_item::menu_activation(char formal(trigger)) {}
00064
00065 const string_array &menu_item::triggers() const { return *_triggers; }
00066
00067 const astring &menu_item::text() const { return *_text; }
00068
00069 const astring &menu_item::description() const { return *_description; }
00070
00072
00073
00075
00076 menu_base::menu_base(const astring &title, const menu_item ¶meters)
00077 : _title(new astring(title)),
00078 _parameters(new menu_item(parameters)),
00079 _items(new menu_common_amorph),
00080 _menus(new menu_common_amorph)
00081 {
00082 }
00083
00084 menu_base::~menu_base()
00085 {
00086 WHACK(_title);
00087 WHACK(_menus);
00088 WHACK(_items);
00089 }
00090
00091 bool menu_base::validate(bool recursive)
00092 {
00093 if (recursive){}
00094
00095 return false;
00096 }
00097
00098 astring menu_base::text_form() const
00099 {
00100
00101 return "";
00102 }
00103
00104 astring menu_base::recursive_text_form() const
00105 {
00106
00107 return "";
00108 }
00109
00110 int menu_base::items() const { return _items->elements(); }
00111
00112 void menu_base::add_item(menu_item *to_invoke)
00113 {
00114 if (!to_invoke) return;
00115 *_items += to_invoke;
00116 }
00117
00118 menu_item *menu_base::get_item(int index)
00119 {
00120 bounds_return(index, 0, _items->elements(), NIL);
00121 return dynamic_cast<menu_item *>(_items->borrow(index));
00122 }
00123
00124 bool menu_base::zap_item(int index)
00125 {
00126 bounds_return(index, 0, _items->elements(), false);
00127 _items->zap(index, index);
00128 return true;
00129 }
00130
00131 bool menu_base::enable_item(int index, bool enable)
00132 {
00133 bounds_return(index, 0, _items->elements(), false);
00134 _items->borrow(index)->enable(enable);
00135 return true;
00136 }
00137
00138 int menu_base::submenus() const { return _menus->elements(); }
00139
00140 void menu_base::add_submenu(menu_base *sub)
00141 {
00142 if (!sub) return;
00143 _menus->append(sub);
00144 }
00145
00146 menu_base *menu_base::get_submenu(int index)
00147 {
00148 bounds_return(index, 0, _menus->elements(), NIL);
00149 return dynamic_cast<menu_base *>(_menus->borrow(index));
00150 }
00151
00152 bool menu_base::zap_submenu(int index)
00153 {
00154 bounds_return(index, 0, _menus->elements(), false);
00155 _menus->zap(index, index);
00156 return true;
00157 }
00158
00159 bool menu_base::enable_submenu(int index, bool enable)
00160 {
00161 bounds_return(index, 0, _menus->elements(), false);
00162 _menus->borrow(index)->enable(enable);
00163 return true;
00164 }
00165
00166 menu_common_base *menu_base::evaluate_trigger(char trigger)
00167 {
00168
00169 if (!trigger){}
00170 return NIL;
00171 }
00172
00173 void menu_base::activate()
00174 {
00175
00176 }
00177
00178
00179
00180