00001 #ifndef __UI_Value__
00002 #define __UI_Value__
00003
00004 #include "UI_API.h"
00005 #include <iostream.h>
00006 #include <SYS/SYS_Types.h>
00007 #include <UT/UT_Pointers.h>
00008 #include "UI_Object.h"
00009
00010
00011
00012
00013
00014
00015 enum UI_ValueType {
00016 UI_VALUE_FLOAT,
00017 UI_VALUE_INTEGER,
00018 UI_VALUE_STRING,
00019 UI_VALUE_FLOAT_ARRAY,
00020 UI_VALUE_INT_ARRAY,
00021 UI_VALUE_STRING_ARRAY,
00022 UI_VALUE_POINTER
00023 };
00024
00025 enum UI_Reason {
00026 UI_NO_REASON,
00027 UI_VALUE_CHANGED,
00028 UI_VALUE_ACTIVE,
00029 UI_VALUE_START,
00030 UI_VALUE_NEW,
00031 UI_VALUE_RANGE_CHANGED,
00032 UI_VALUE_PICKED,
00033 UI_VALUE_LOCATED,
00034 UI_VALUE_ITEMS_CHANGED
00035 };
00036
00037 #define UI_STEP_BIG 4
00038
00039 enum UI_StepType {
00040 UI_STEP_INCREMENT = 1,
00041 UI_STEP_DECREMENT = 2,
00042 UI_STEP_INCREMENT_BIG = (UI_STEP_INCREMENT | UI_STEP_BIG),
00043 UI_STEP_DECREMENT_BIG = (UI_STEP_DECREMENT | UI_STEP_BIG)
00044 };
00045
00046 class UI_Event;
00047 class UT_Color;
00048 class UT_String;
00049 class UT_IStream;
00050
00051
00052
00053 class UI_API UI_Value : public UI_Object
00054 {
00055 public:
00056 UI_Value();
00057 UI_Value(int i);
00058 UI_Value(fpreal32 f);
00059 UI_Value(fpreal64 f);
00060 UI_Value(float fp[], int n);
00061 UI_Value(int ip[], int n);
00062 UI_Value(char *ssp[], int n);
00063 UI_Value(const char *s);
00064 UI_Value(const UI_Value &v);
00065 UI_Value(void *p);
00066
00067 virtual ~UI_Value();
00068
00069 void setValue(long l) { setValue((int)l); }
00070 virtual void setValue(int i);
00071 virtual void setValue(fpreal32 f);
00072 virtual void setValue(fpreal64 f);
00073 virtual void setValue(fpreal32 f, int n);
00074 virtual void setValue(fpreal64 f, int n);
00075 virtual void setValue(int i, int n);
00076 virtual void setValue(const char *s, int n);
00077 virtual void setValue(const float fp[], int n);
00078 virtual void setValue(const int ip[], int n);
00079 virtual void setValue(const char *const ssp[], int n);
00080 virtual void setValue(const char *s);
00081 virtual void setValue(const UI_Value &v);
00082 virtual void setValue(void *pointer);
00083
00084 void setValue(const UT_Color &c);
00085 void stringPrintf(const char *fmt, ...);
00086
00087 virtual void changed(UI_Object *by,
00088 UI_Reason reason = UI_VALUE_CHANGED,
00089 UI_DeviceEvent *state = 0);
00090
00091
00092
00093
00094
00095
00096 void triggerImmediate(UI_Object *by,
00097 UI_Reason reason = UI_VALUE_CHANGED,
00098 UI_DeviceEvent *state = 0);
00099
00100 virtual void enable(int state);
00101 virtual void override(int state, int);
00102 virtual void open(int state);
00103 virtual void refresh();
00104
00105
00106
00107 bool areAnyFeelClientsOpen();
00108
00109 virtual void handleEvent(UI_Event *event);
00110 virtual void deleteReferences(UI_Object *to_whom);
00111
00112 virtual void setSteps(float mysmall, float large);
00113 virtual void setRange(float min, float max);
00114 virtual void getRange(float *min, float *max) const;
00115
00116 virtual void rangeCheck();
00117 virtual int step(UI_StepType how);
00118
00119 int save(ostream &os) const;
00120 bool load(UT_IStream &is);
00121
00122 void setFormat(const char *fmt) { myFormat = fmt; }
00123 const char *getFormat() const { return myFormat; }
00124
00125 void getValue(int *ip) const;
00126 void getValue(float *fp) const;
00127 void getValue(char *&s) const;
00128 void getValue(float *fp, int n) const;
00129 void getValue(int *ip, int n) const;
00130 void getValue(char **ssp, int n) const;
00131 void getValue(char *sp, int bufsize) const;
00132 void getValue(char *sp, int bufsize, const char *format) const;
00133 void getValue(UT_String &value) const;
00134 void getValue(UI_Value &v) const;
00135 void getValue(void **pp) const;
00136
00137 int getArrayLength() const;
00138
00139 UI_ValueType getType() const { return type; }
00140 virtual int isVector() const { return 0; }
00141
00142 void addInterest(UI_Object *client, UI_EventMethod method,
00143 bool check_dup = false);
00144 void addPriorityInterest(UI_Object *client, UI_EventMethod method,
00145 bool check_dup = false);
00146 bool hasInterest(UI_Object *in, UI_EventMethod method);
00147 bool hasInterest(UI_Object *obj);
00148 void removeInterest(UI_Object *in, UI_EventMethod method);
00149 void removeInterest(UI_Object *client);
00150 void removeAllInterests();
00151
00152
00153
00154
00155
00156 const char *getString() const;
00157 void setString(char *sp);
00158 char *stealString();
00159 void expandEnvironment();
00160 void expandTilde();
00161
00162 operator const char *() const;
00163 operator int () const;
00164 operator bool () const;
00165 operator long () const;
00166 operator float () const;
00167 operator void *() const;
00168
00169 void operator =(int i) { setValue(i); }
00170 void operator =(long l) { setValue(l); }
00171 void operator =(fpreal32 f) { setValue(f); }
00172 void operator =(fpreal64 f) { setValue(f); }
00173 void operator =(const char *s) { setValue(s); }
00174 void operator =(const UI_Value &v) { setValue(v); }
00175 void operator =(void *p) { setValue(p); }
00176 void operator =(const UT_Color &c) { setValue(c); }
00177
00178 void operator +=(const UI_Value &v);
00179 void operator +=(const char *string);
00180
00181 int operator ==(const UI_Value &v) const;
00182 int operator ==(const float fp[]) const;
00183 int operator ==(const int ip[]) const;
00184 int operator ==(const char *ssp[]) const;
00185 int operator ==(float f) const;
00186 int operator ==(int i) const;
00187 int operator ==(const char *s) const;
00188 int operator ==(void *p) const;
00189
00190 float & operator [](float index);
00191 int & operator [](int index);
00192
00193 virtual const char *className() const;
00194
00195
00196 unsigned int getNumInterested() const;
00197 UI_Object *getInterest(int index) const;
00198
00199
00200
00201 bool isFreezable() const { return myFreezeFlag; }
00202 virtual void setFreezable(bool f) { myFreezeFlag = f; }
00203
00204 protected:
00205 union {
00206 int i;
00207 float f;
00208 float *a;
00209 int *j;
00210 char *s;
00211 char **ss;
00212 void *p;
00213 } value;
00214 const char *myFormat;
00215 UT_Pointers *interests;
00216 UI_ValueType type;
00217 bool myFreezeFlag;
00218
00219 private:
00220 void init();
00221 void zap();
00222
00223 void addMyInterest(UI_Object *client,
00224 UI_EventMethod method,
00225 bool check_dup,
00226 bool priority);
00227
00228 friend ostream &operator<<(ostream &os, const UI_Value &v)
00229 {
00230 v.save(os);
00231 return os;
00232 }
00233 };
00234
00235 #endif