HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UI_Value.h
Go to the documentation of this file.
1 #ifndef __UI_Value__
2 #define __UI_Value__
3 
4 #include "UI_API.h"
5 #include "UI_Object.h"
6 #include <SYS/SYS_Types.h>
7 #include <iosfwd>
8 #include <deque>
9 
10 /*
11  * A UI_Value is a utility class which maintains a single value of
12  * variable type and provides conversions between types.
13  */
14 
23 };
24 
25 enum UI_Reason {
26  UI_NO_REASON, // event was likely explicitly generated
27  UI_VALUE_CHANGED, // mouse up
28  UI_VALUE_ACTIVE, // mouse drag
29  UI_VALUE_START, // mouse down
30  UI_VALUE_NEW, // dependent added to UI_Value
31  UI_VALUE_RANGE_CHANGED, // UI_ScrollValue range changed
32  UI_VALUE_PICKED, // quick mouse down and release without drag
33  UI_VALUE_LOCATED, // mouse hover (only if wantsLocates() is true)
34  UI_VALUE_ITEMS_CHANGED // only generated by UI_StringList (and subclasses)
35 };
36 
37 #define UI_STEP_BIG 4
38 
44 };
45 
46 class UI_Event;
47 class UT_Color;
48 class UT_String;
49 class UT_StringArray;
50 class UT_StringHolder;
51 class UT_StringRef;
52 class UT_IStream;
53 class ui_Client;
54 
55 //====================================================================
56 
57 class UI_API UI_Value : public UI_Object
58 {
59 public:
60  UI_Value();
61  explicit UI_Value(int32 i);
62  explicit UI_Value(int64 i);
63  explicit UI_Value(fpreal32 f);
64  explicit UI_Value(fpreal64 f);
65  explicit UI_Value(fpreal32 fp[], exint n);
66  explicit UI_Value(fpreal64 dp[], exint n);
67  explicit UI_Value(int32 ip[], exint n);
68  explicit UI_Value(int64 ip[], exint n);
69  explicit UI_Value(const UT_StringArray &ssp);
70  explicit UI_Value(const char *s);
71  explicit UI_Value(const UI_Value &v);
72 
73  virtual ~UI_Value();
74 
75  virtual void setValue(int32 i);
76  virtual void setValue(int64 i);
77  virtual void setValue(fpreal64 f);
78  virtual void setValue(fpreal64 f, exint n);
79  virtual void setValue(int32 i, exint n);
80  virtual void setValue(int64 i, exint n);
81  virtual void setValue(const fpreal32 fp[], exint n);
82  virtual void setValue(const fpreal64 dp[], exint n);
83  virtual void setValue(const int32 ip[], exint n);
84  virtual void setValue(const int64 ip[], exint n);
85  virtual void setValue(const UT_StringArray &ssp);
86  virtual void setValue(const char *s);
87  virtual void setValue(const UI_Value &v);
88  void setValue(const UT_Color &c);
89  void setPointerValue(void *p);
90  void stringPrintf(const char *fmt, ...);
91 
92  virtual void changed(UI_Object *by,
93  UI_Reason reason = UI_VALUE_CHANGED,
94  UI_DeviceEvent *state = 0);
95  // This method is similar to "changed" but it triggers the callback events
96  // immediately (bypassing the event queue). It also only notifies the
97  // objects that have added interests in this value. Not the immediate
98  // dependents. **This should only be used in special circumstances.**
99  void triggerImmediate(UI_Object *by,
100  UI_Reason reason = UI_VALUE_CHANGED,
101  UI_DeviceEvent *state = 0);
102  // This method is similar to "triggerImmediate" but it notifies the
103  // immediate dependents rather than the objects that have added interests
104  // in this value. **This should only be used in special circumstances.**
105  void triggerDependents(UI_Object *by,
106  UI_Reason reason = UI_VALUE_CHANGED,
107  UI_DeviceEvent *state = 0);
108 
109  virtual void enable(bool state); // Sends enable event to dependents
110  virtual void visible(bool state); // Sends visible event to dependents
111  virtual void override(bool state, int);// Sends override event to dependents
112  virtual void open(bool state); // Sends open/close event to dependents
113  virtual void refresh(); // Sends redraw in place events
114 
115  // This ugly hack attempts to determine the open state of UI_Feel clients
116  // which are open. It returns true only if *any* of them are open.
117  bool areAnyFeelClientsOpen() const;
118 
119  virtual void handleEvent(UI_Event *event);
120  virtual void deleteReferences(UI_Object *to_whom);
121 
122  virtual void setSteps(fpreal mysmall, fpreal large);
123  virtual void setRange(fpreal min, fpreal max);
124  virtual void getRange(fpreal *min, fpreal *max) const;
125 
126  virtual void rangeCheck();
127  virtual int step(UI_StepType how);
128 
129  int save(std::ostream &os) const;
130  bool load(UT_IStream &is);
131 
132  void setFormat(const char *fmt) { myFormat = fmt; }
133  const char *getFormat() const { return myFormat; }
134 
135  void getValue(int32 *ip) const;
136  void getValue(int64 *ip) const;
137  void getValue(fpreal32 *fp) const;
138  void getValue(fpreal64 *fp) const;
139  void getValue(fpreal32 *fp, exint n) const;
140  void getValue(fpreal64 *dp, exint n) const;
141  void getValue(int32 *ip, exint n) const;
142  void getValue(int64 *ip, exint n) const;
143  void getValue(char *sp, exint bufsize) const;
144  void getValue(char *sp, exint bufsize, const char *format) const;
145  void getValue(UT_String &s) const;
146  void getValue(UT_StringHolder &s) const;
147  void getValue(UT_StringArray &ssp, exint n) const;
148  void getValue(UI_Value &v) const;
149  void getValue(UT_Color &color) const;
150  void getValue(void **pp) const;
151 
152  void getArrayValue(fpreal *d, exint index) const;
153  void getArrayValue(int32 *d, exint index) const;
154  void getArrayValue(int64 *d, exint index) const;
155  exint getArrayLength() const;
156 
157  UI_ValueType getType() const { return type; }
158  virtual int isVector() const { return 0; }
159 
160  void addInterest(UI_Object *client, UI_EventMethod method,
161  bool check_dup = false);
162  void addPriorityInterest(UI_Object *client, UI_EventMethod method,
163  bool check_dup = false);
164  bool hasInterest(UI_Object *in, UI_EventMethod method);
165  bool hasInterest(UI_Object *obj);
166  void removeInterest(UI_Object *in, UI_EventMethod method);
167  void removeInterest(UI_Object *client);
168  void removeAllInterests();
169 
170  // Note: setString sets the char * value whereas setValue(char *) does
171  // a strdup. (ie UI_Value will own the string you set with setString)
172  const char *getString() const; // Short cuts for string manipulation.
173  void setString(char *sp);
174  char *stealString(); // Take the string away from the value.
175 
176  // Expand environment variables and, on OSX and Linux, the ~ character.
177  void expandEnvironment();
178 
179  operator const char *() const;
180  operator bool() const;
181  operator int32() const;
182  operator int64() const;
183  operator fpreal32() const;
184  operator fpreal64() const;
185  operator void *() const;
186 
187  void operator=(int32 i) { setValue(i); }
188  void operator=(int64 i) { setValue(i); }
189  void operator=(fpreal32 f) { setValue(f); }
190  void operator=(fpreal64 f) { setValue(f); }
191  void operator=(const char *s) { setValue(s); }
192  void operator=(const UI_Value &v) { setValue(v); }
193  void operator=(const UT_Color &c) { setValue(c); }
194 
195  bool operator==(const UI_Value &v) const;
196  bool operator==(const fpreal32 fp[]) const;
197  bool operator==(const fpreal64 fp[]) const;
198  bool operator==(const int32 ip[]) const;
199  bool operator==(const int64 ip[]) const;
200  bool operator==(const UT_StringArray &ssp) const;
201  bool operator==(fpreal64 f) const;
202  bool operator==(fpreal32 f) const;
203  bool operator==(int32 i) const;
204  bool operator==(int64 i) const;
205  bool operator==(const char *s) const;
206 
207  virtual const char *className() const;
208 
209  // Return the number of interests expressed in this value
210  unsigned int getNumInterested() const;
211  UI_Object *getInterest(int index) const;
212 
213  // Set to true to track
215  {
218  TL_VALUE
219  };
220 
221  bool isTraced() const { return myTraceLevel != TL_NONE; }
222  virtual void setTraceLevel(TraceLevel tl) { myTraceLevel = tl; }
223 
224 protected:
225  union {
230  char *s;
231  char **ss;
232  void *p;
233  } value;
234  const char *myFormat;
236  TraceLevel myTraceLevel:2;
237 
238  void showTrace();
239 
240 private:
241  void init();
242  void zap();
243 
244  void addMyInterest(UI_Object *client,
246  bool check_dup,
247  bool priority);
248  void sendEventToInterests(UI_Object *by, UI_Event &event,
249  bool immediate);
250 
251  friend std::ostream &operator<<(std::ostream &os, const UI_Value &v)
252  {
253  v.save(os);
254  return os;
255  }
256 
257  typedef std::deque<ui_Client *> ui_ClientList;
258  ui_ClientList::iterator ibegin() { return myInterests.begin(); }
259  ui_ClientList::iterator iend() { return myInterests.end(); }
260 
261  ui_ClientList myInterests;
262 };
263 
264 #endif
friend std::ostream & operator<<(std::ostream &os, const UI_Value &v)
Definition: UI_Value.h:251
GLenum GLuint GLsizei bufsize
Definition: glcorearb.h:1817
bool isTraced() const
Definition: UI_Value.h:221
exint * j
Definition: UI_Value.h:229
void operator=(int32 i)
Definition: UI_Value.h:187
void operator=(const UI_Value &v)
Definition: UI_Value.h:192
virtual void setTraceLevel(TraceLevel tl)
Definition: UI_Value.h:222
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128
const GLdouble * v
Definition: glcorearb.h:836
const char * getFormat() const
Definition: UI_Value.h:133
void setFormat(const char *fmt)
Definition: UI_Value.h:132
GLuint color
Definition: glcorearb.h:1260
exint i
Definition: UI_Value.h:226
UI_ValueType getType() const
Definition: UI_Value.h:157
void operator=(fpreal64 f)
Definition: UI_Value.h:190
png_uint_32 i
Definition: png.h:2877
void operator=(fpreal32 f)
Definition: UI_Value.h:189
struct _cl_event * event
Definition: glcorearb.h:2960
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
char * s
Definition: UI_Value.h:230
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
long long int64
Definition: SYS_Types.h:100
virtual void handleEvent(UI_Event *event)
void operator=(const char *s)
Definition: UI_Value.h:191
png_FILE_p fp
Definition: png.h:2028
GLdouble n
Definition: glcorearb.h:2007
GLfloat f
Definition: glcorearb.h:1925
void * p
Definition: UI_Value.h:232
int64 exint
Definition: SYS_Types.h:109
virtual int isVector() const
Definition: UI_Value.h:158
double fpreal64
Definition: SYS_Types.h:185
int method
Definition: png.h:1924
fpreal * a
Definition: UI_Value.h:228
int int32
Definition: SYS_Types.h:28
virtual int open(float queuesize)
int save(std::ostream &os) const
fpreal d
Definition: UI_Value.h:227
UI_Reason
Definition: UI_Value.h:25
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:107
GLsizei const GLfloat * value
Definition: glcorearb.h:823
double fpreal
Definition: SYS_Types.h:263
typedef int
Definition: png.h:1175
const char * myFormat
Definition: UI_Value.h:234
GLuint index
Definition: glcorearb.h:785
virtual void deleteReferences(UI_Object *to_whom)
void(UI_Object::* UI_EventMethod)(UI_Event *)
Definition: UI_Object.h:42
virtual const char * className() const
void operator=(const UT_Color &c)
Definition: UI_Value.h:193
#define UI_API
Definition: UI_API.h:10
UI_StepType
Definition: UI_Value.h:39
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
#define UI_STEP_BIG
Definition: UI_Value.h:37
void operator=(int64 i)
Definition: UI_Value.h:188
float fpreal32
Definition: SYS_Types.h:184
char ** ss
Definition: UI_Value.h:231
UI_ValueType
Definition: UI_Value.h:15