00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __GR_OptionTable__
00022 #define __GR_OptionTable__
00023
00024 #include "GR_API.h"
00025 #include <UT/UT_SymbolTable.h>
00026 #include <UT/UT_PtrArray.h>
00027 #include <UT/UT_Notifier.h>
00028
00029 class GR_OptionTemplate;
00030 class GR_UserOption;
00031
00032 class GR_API GR_OptionTableEvent
00033 {
00034 public:
00035 enum GR_OptionTableEventType
00036 {
00037 OPTION_ADDED,
00038 OPTION_DELETED,
00039 OPTION_CHANGED
00040 };
00041
00042 GR_OptionTableEvent( GR_OptionTableEventType type, GR_UserOption *option,
00043 int id )
00044 : myEventType(type), myOption(option), myOptionId(id) {}
00045
00046 GR_OptionTableEventType myEventType;
00047 GR_UserOption *myOption;
00048 int myOptionId;
00049 };
00050
00051 class GR_API GR_OptionTable
00052 {
00053 public:
00054 GR_OptionTable();
00055 virtual ~GR_OptionTable();
00056
00057
00058 void addTemplate(GR_OptionTemplate *tplate);
00059
00060
00061 int getNumTemplates() const;
00062 GR_OptionTemplate *getTemplate(int i) const;
00063
00064
00065 int getNumOptions() const { return myOptions.entries(); }
00066 const GR_UserOption *getOption(int i) const { return myOptions(i); }
00067
00068 GR_UserOption *createOption(const char *type, const char *name);
00069 bool destroyOption(const char *name);
00070 bool renameOption(const char *old_name,
00071 const char *new_name, bool notify);
00072 void optionChanged(const char *name);
00073
00074 GR_UserOption *getOption(const char *name);
00075 int getOptionId(const char *name) const;
00076 GR_UserOption *getOptionById(int unique_id)
00077 {
00078 if( unique_id >= 0 && unique_id <
00079 myOptionsByID.entries() )
00080 return myOptionsByID(unique_id);
00081 return 0;
00082 }
00083
00084
00085
00086 UT_NotifierImpl<GR_OptionTableEvent &>
00087 &getEventNotifier() { return myEventNotifier; }
00088
00089
00090
00091
00092 static void overrideDefinitionFile(const char *filename);
00093
00094 void saveDefaultOptionDefinitions();
00095 void loadDefaultOptionDefinitions();
00096
00097
00098 bool saveOptions(ostream &os, int indent = 0) const;
00099 bool loadOptions(UT_IStream &is);
00100
00101 private:
00102 void addFactoryTemplates();
00103
00104 protected:
00105 UT_PtrArray<GR_OptionTemplate *> myTemplates;
00106 UT_SymbolTable myTemplateLUT;
00107
00108 UT_PtrArray<GR_UserOption *> myOptions;
00109 UT_SymbolTable myOptionsLUT;
00110
00111
00112 UT_PtrArray<GR_UserOption *> myOptionsByID;
00113
00114
00115
00116 UT_NotifierImpl<GR_OptionTableEvent &> myEventNotifier;
00117 };
00118
00119 GR_API extern GR_OptionTable *GRgetOptionTable();
00120
00121 #endif
00122