menu_base.h

Go to the documentation of this file.
00001 //note: in progress.
00002 
00003 #ifndef MENU_BASE_CLASS
00004 #define MENU_BASE_CLASS
00005 
00006 /*****************************************************************************\
00007 *                                                                             *
00008 *  Name   : menu_base                                                         *
00009 *  Author : Chris Koeritz                                                     *
00010 *                                                                             *
00011 *******************************************************************************
00012 * Copyright (c) 2003-$now By Author.  This program is free software; you can  *
00013 * redistribute it and/or modify it under the terms of the GNU General Public  *
00014 * License as published by the Free Software Foundation; either version 2 of   *
00015 * the License or (at your option) any later version.  This is online at:      *
00016 *     http://www.fsf.org/copyleft/gpl.html                                    *
00017 * Please send any updates to: fred@gruntose.com                               *
00018 \*****************************************************************************/
00019 
00020 #include "mechanisms_dll.h"
00021 
00022 #include <basis/object_base.h>
00023 
00024 // forward.
00025 class menu_common_amorph;
00026 
00028 
00030 
00031 class MECHANISMS_CLASS_STYLE menu_common_base : public virtual object_base
00032 {
00033 public:
00034   virtual ~menu_common_base();
00035 
00036   inline bool enabled() const { return _enabled; }
00037   inline void enable(bool enable = true) { _enabled = enable; }
00038 
00039 private:
00040   bool _enabled;  
00041 };
00042 
00044 
00046 
00047 class MECHANISMS_CLASS_STYLE menu_item
00048 : public menu_common_base
00049 {
00050 public:
00051   menu_item(const string_array &triggers, const istring &text,
00052           const istring &description);
00054 
00057   menu_item(const menu_item &to_copy);
00058 
00059   virtual ~menu_item();
00060 
00061   menu_item &operator =(const menu_item &to_copy);
00062 
00063   IMPLEMENT_CLASS_NAME("menu_item");
00064 
00065   const string_array &triggers() const;
00066   const istring &text() const;
00067   const istring &description() const;
00068 
00069   virtual void menu_activation(char trigger);
00071 
00073 private:
00074   string_array *_triggers;  
00075   istring *_text;  
00076   istring *_description;  
00077 };
00078 
00080 
00082 
00086 class MECHANISMS_CLASS_STYLE menu_base : public menu_common_base
00087 {
00088 public:
00089   menu_base(const istring &title, const menu_item &parameters);
00090     //<! constructs a menu where the "title" is the name for this menu.
00094   virtual ~menu_base();
00095 
00096   IMPLEMENT_CLASS_NAME("menu_base");
00097 
00098   bool validate(bool recursive = true);
00100 
00101   istring text_form() const;
00103 
00105   istring recursive_text_form() const;
00107 
00108   menu_common_base *evaluate_trigger(char trigger);
00110 
00114   virtual void activate();
00116 
00123   // note about the methods here: the menu_base takes over responsibility for
00124   // pointers it is handed.  do not delete the items after adding them or
00125   // get an item and then delete it.
00126   // also, the indices for menu items are separate from the indices for the
00127   // sub-menus.
00128 
00129   // menu item manipulators.  the indexes here range from 0 to items() - 1.
00130   int items() const;  
00131   void add_item(menu_item *to_invoke);
00133   menu_item *get_item(int index);
00135   bool zap_item(int index);
00137   bool enable_item(int index, bool enable = true);
00139 
00140   // submenu manipulation support.  these range from 0 to submenus() - 1.
00141   int submenus() const;  
00142   void add_submenu(menu_base *sub);  
00143   menu_base *get_submenu(int index);
00145   bool zap_submenu(int index);
00147   bool enable_submenu(int index, bool enable = true);
00149 
00150 private:
00151   istring *_title;  
00152   menu_item *_parameters;  
00153   menu_common_amorph *_items;  
00154   menu_common_amorph *_menus;  
00155 };
00156 
00157 #endif
00158 

Generated on Fri Nov 28 04:29:16 2008 for HOOPLE Libraries by  doxygen 1.5.1