HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UI_Object.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UI_Object.h
7  *
8  * COMMENTS:
9  *
10  * A UI_Object is the base class for objects that are organized in a
11  * hierarchy and are capable of receiving UI_Events.
12  *
13  */
14 #ifndef __UI_Object__
15 #define __UI_Object__
16 
17 #include "UI_API.h"
18 #include "UI_EventType.h"
19 
20 #include <UT/UT_Assert.h>
21 #include <hboost/container/stable_vector.hpp>
22 #include <list>
23 
24 class RE_Render;
25 class UT_String;
26 class UI_Event;
27 class UI_Manager;
28 class UI_Queue;
29 class UI_DeviceEvent;
30 class UI_Object;
31 class UI_Value;
32 class UI_HotkeyEcho;
33 
34 //
35 // Turn the following define to 1 to perform proxy pointer referencing of
36 // objects. Turn it to 0 to disable the proxy pointers. Proxy pointers
37 // prevent UI_Values sending events to deleted objects (which shouldn't happen
38 // in real life)
39 //
40 #define UI_ENABLE_PROXY_POINTERS 1
41 
43 
44 // stable_vector is a hybrid of list and vector; giving random access and
45 // stable iterators upon insert/erase (except for an element pointed to),
46 // albeit with the loss of contiguity.
47 typedef hboost::container::stable_vector<UI_Object *> UI_ObjectList;
48 typedef hboost::container::stable_vector<UI_Value *> UI_ValueList;
49 
51 {
52 public:
53  UI_Object();
54 
55  virtual ~UI_Object();
56 
57  // !!! WARNING: Do NOT derive from UT_NonCopyable due to Visual C++ bug !!!
58  // !!! Otherwise Visual C++ will start causing subclass callback member
59  // !!! method pointers (of single inheriance chains) to become larger than
60  // !!! UI_EventMethod.
61  UI_Object(const UI_Object &) = delete;
62  UI_Object &operator=(const UI_Object &) = delete;
63  // !!! WARNING: Do NOT derive from UT_NonCopyable due to Visual C++ bug !!!
64 
65  virtual void handleEvent(UI_Event *event);
66  virtual int interestingEvent(UI_EventType t, UI_DeviceEvent *event) const;
67  virtual void deleteReferences(UI_Object *to_whom);
68 
69  UI_Object *getParent() const { return myParent; }
70  void setParent(UI_Object *p) { myParent = p; }
71  bool isAncestor(const UI_Object *who) const;
72 
73  void addDependent(UI_Object *who);
74  bool removeDependent(UI_Object *who);
75  bool replaceDependent(UI_Object *who, UI_Object *with);
76  bool isDependent(UI_Object *who) const;
77  bool hasDependents() const { return !myDependents.empty(); }
78  const UI_ObjectList &dependents() const { return myDependents; }
79 
80  void sendEvent(const UI_Event &e) const;
81  void distributeEvent(UI_Event *event, int upwards);
82  void relayEvent(UI_Event *event, UI_Object *target);
83  void generateEvent(UI_EventType t, UI_Object *target);
84  void purgeEvents(UI_EventType t, UI_Object *target,
86 
87  // This method is similar to "distributeEvent()" but it bypasses the event
88  // queue, triggering the events on the dependents immediately.
89  // **This should only be used in special circumstances.**
90  void triggerImmediateEvent(UI_Event *event, int upwards);
91 
92  virtual const char *className() const;
93 
94 #if UI_ENABLE_PROXY_POINTERS == 1
95  int getProxyId();
96 #endif
97 
98  void bumpQueueCount(int dir) { myQueueCount += dir; }
99 
100 
101  // only works in debug.
102  void setName(const char *symbolName);
103  const char *getName() const;
104  void buildFullPath(UT_String &string) const;
105 
106  // Debug events which target this UI_Object coming in from given UI_Value.
107  // You must also enable the define UI_QUEUE_DEBUG_TARGET_ORIGIN in
108  // UI_Queue.C in order to use this method. The type is optional; if
109  // specified, only events of that type are monitored.
110  // Either object or value (or both) can be specified.
111  void debugQueueEventsFor(
112  const UI_Value *value,
113  const char *name,
114  UI_EventType t = UI_EVENT_NO_EVENT) const;
115 
116 
117  static UI_Manager *getManager() { return theUIManager; }
118  static UI_Queue *getInputQueue() { return theUIQueue; }
119 
120  static int keycmp(const char *, int key);
121  static int keycmp(const char *, int key,
122  const UI_HotkeyEcho &);
123 
124  const UI_ValueList &valueInterests() const { return myValueInterests; }
125 
126 
127  // only UI_Value should call these methods.
128  void interestedInValue(UI_Value *);
129  void removeValueInterest(UI_Value *);
130 
131 protected:
132  UI_ObjectList &dependents() { return myDependents; }
133 
134  // This is the function called by the UI_Manager at the start of a call
135  // to terminate, but only if this object has been added to the UI_Manager
136  // list of pre-terminate callbacks.
137  virtual void preTerminateCallback()
138  { }
139 
140 private:
141  UI_Object *myParent;
142  UI_ObjectList myDependents;
143  UI_ValueList myValueInterests;
144  int myQueueCount;
145 #if UI_ENABLE_PROXY_POINTERS == 1
146  int myProxyId;
147 #endif
148 #if defined(UI_DEBUG_OBJECT_NAME)
149  char *myName;
150 #endif
151  bool myDestroying : 1;
152 
153  friend class UI_Manager;
154  void setManager(UI_Manager *m, UI_Queue *q);
155 
156  static UI_Manager *theUIManager;
157  static UI_Queue *theUIQueue;
158 };
159 
160 #endif
const UI_ObjectList & dependents() const
Definition: UI_Object.h:78
hboost::container::stable_vector< UI_Object * > UI_ObjectList
Definition: UI_Object.h:47
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
UI_Object * getParent() const
Definition: UI_Object.h:69
void setParent(UI_Object *p)
Definition: UI_Object.h:70
const UI_ValueList & valueInterests() const
Definition: UI_Object.h:124
struct _cl_event * event
Definition: glcorearb.h:2960
static UI_Manager * getManager()
Definition: UI_Object.h:117
virtual void preTerminateCallback()
Definition: UI_Object.h:137
UI_ObjectList & dependents()
Definition: UI_Object.h:132
bool hasDependents() const
Definition: UI_Object.h:77
void bumpQueueCount(int dir)
Definition: UI_Object.h:98
int method
Definition: png.h:1924
UI_EventType
Definition: UI_EventType.h:20
GLenum target
Definition: glcorearb.h:1666
GLuint const GLchar * name
Definition: glcorearb.h:785
GLsizei const GLfloat * value
Definition: glcorearb.h:823
static UI_Queue * getInputQueue()
Definition: UI_Object.h:118
hboost::container::stable_vector< UI_Value * > UI_ValueList
Definition: UI_Object.h:48
void(UI_Object::* UI_EventMethod)(UI_Event *)
Definition: UI_Object.h:42
#define UI_API
Definition: UI_API.h:10