first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / graphiq / library / user_interface / menu_base.cpp
1
2
3
4 //note: in progress.
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 #include "menu_base.h"
21
22 #include <structures/string_array.h>
23 #include <structures/amorph.h>
24
25 class menu_common_amorph : public amorph<menu_common_base> {};
26
27 //////////////
28
29 menu_common_base::~menu_common_base() {}
30
31 //////////////
32
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))
38 {}
39
40 menu_item::menu_item(const menu_item &to_copy)
41 : root_object(),
42   menu_common_base(),
43   _triggers(new string_array),
44   _text(new astring),
45   _description(new astring)
46 { *this = to_copy; }
47
48 menu_item::~menu_item()
49 {
50   WHACK(_text);
51   WHACK(_description);
52 }
53
54 menu_item &menu_item::operator =(const menu_item &to_copy)
55 {
56   if (this == &to_copy) return *this;
57   *_triggers = *to_copy._triggers;
58   *_text = *to_copy._text;
59   *_description = *to_copy._description;
60   return *this;
61 }
62
63 void menu_item::menu_activation(char formal(trigger)) {}
64
65 const string_array &menu_item::triggers() const { return *_triggers; }
66
67 const astring &menu_item::text() const { return *_text; }
68
69 const astring &menu_item::description() const { return *_description; }
70
71 //////////////
72
73 //call this when menu invoked.
74 ///  virtual bool menu_item_activity() = 0;
75
76 menu_base::menu_base(const astring &title, const menu_item &parameters)
77 : _title(new astring(title)),
78   _parameters(new menu_item(parameters)),
79   _items(new menu_common_amorph),
80   _menus(new menu_common_amorph)
81 {
82 }
83
84 menu_base::~menu_base()
85 {
86   WHACK(_title);
87   WHACK(_menus);
88   WHACK(_items);
89 }
90
91 bool menu_base::validate(bool recursive)
92 {
93 if (recursive){}
94 //hmmm: implement this too....
95 return false;
96 }
97
98 astring menu_base::text_form() const
99 {
100 //hmmm: implement this too....
101 return "";
102 }
103
104 astring menu_base::recursive_text_form() const
105 {
106 //hmmm: implement this too....
107 return "";
108 }
109
110 int menu_base::items() const { return _items->elements(); }
111
112 void menu_base::add_item(menu_item *to_invoke)
113 {
114   if (!to_invoke) return;
115   *_items += to_invoke;
116 }
117
118 menu_item *menu_base::get_item(int index)
119 {
120   bounds_return(index, 0, _items->elements(), NIL);
121   return dynamic_cast<menu_item *>(_items->borrow(index));
122 }
123
124 bool menu_base::zap_item(int index)
125 {
126   bounds_return(index, 0, _items->elements(), false);
127   _items->zap(index, index);
128   return true;
129 }
130
131 bool menu_base::enable_item(int index, bool enable)
132 {
133   bounds_return(index, 0, _items->elements(), false);
134   _items->borrow(index)->enable(enable);
135   return true;
136 }
137
138 int menu_base::submenus() const { return _menus->elements(); }
139
140 void menu_base::add_submenu(menu_base *sub)
141 {
142   if (!sub) return;
143   _menus->append(sub);
144 }
145
146 menu_base *menu_base::get_submenu(int index)
147 {
148   bounds_return(index, 0, _menus->elements(), NIL);
149   return dynamic_cast<menu_base *>(_menus->borrow(index));
150 }
151
152 bool menu_base::zap_submenu(int index)
153 {
154   bounds_return(index, 0, _menus->elements(), false);
155   _menus->zap(index, index);
156   return true;
157 }
158
159 bool menu_base::enable_submenu(int index, bool enable)
160 {
161   bounds_return(index, 0, _menus->elements(), false);
162   _menus->borrow(index)->enable(enable);
163   return true;
164 }
165
166 menu_common_base *menu_base::evaluate_trigger(char trigger)
167 {
168 //hmmm: implement this too....
169 if (!trigger){}
170 return NIL;
171 }
172
173 void menu_base::activate()
174 {
175 //hmmm: implement this too....
176 }
177
178
179
180