Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cXObjEventSink.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cXObjEventSink_H
7 #define _INC_cXObjEventSink_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cXObjPackChild.h"
13 #include "../Scriptable/cScriptableEventsMask.h" // EVENTX_TYPE
14 
15 namespace GrayLib
16 {
19 
21  {
25  EVENTPRI_HIGH = 32, //
26  EVENTPRI_MEDIUM = 64, //
27  EVENTPRI_LOW = 128, //
29  };
30 
32  {
37 
38  EVENTRET_Failed = HRESULT_WIN32_C(ERROR_INVALID_FUNCTION),
39 
41  EVENTRET_NotHandled = S_FALSE,
42 
45  };
46 
48  : public cXObjPackChild
49  {
57 
58  friend class cXObjEventSinks;
59  typedef cXObjPackChild SUPER_t;
60 
61  public:
62  cXObjEventSink(UID_t rid, cAtomRef aSymName, EVENTPRI_TYPE ePriorityLevel = EVENTPRI_MEDIUM);
63  virtual ~cXObjEventSink();
64 
65  static inline bool IsHandledEvent(EVENTRET_TYPE hRes) noexcept
66  {
67  // Do we need to call more handlers ?
68  // EVENTRET_IsHandled(hRes)
69  return (hRes == EVENTRET_Handled || hRes >= EVENTRET_HandledNoDefault);
70  }
71 
72  EVENTPRI_TYPE get_SortValue() const noexcept
73  {
74  return m_ePriorityLevel;
75  }
76 
77  virtual void CopyXObject(const cXObjDef* pDef);
78 
79  // What interface do we want to consume the events? so we can have other higher interfaces that do not!
81 
82  // Dispatch/Invoke.
83  STDMETHOD(s_PropPut)(const cScriptableProp* pProp, const cVariant& vVal) override;
84  STDMETHOD(s_PropGet)(const cScriptableProp* pProp, OUT cVariant& vValRet) override;
85  STDMETHOD(s_Invoke)(const cScriptableMethod* pMethod, const cVariant& vArgs, OUT cVariant& vValRet) override;
86 
87  HRESULT FindEventHandlerN(const ATOMCHAR_t* pszEventName) const;
88  HRESULT RegisterEventHandlerN(const ATOMCHAR_t* pszEventName);
89  bool UnregisterEventHandlerN(const ATOMCHAR_t* pszEventName);
90 
92  {
93  // Assume we handle no events yet.
94  m_EventsHandled.ClearEventHandlers();
95  }
97  {
98  // Say we handle a method from get_EventSinkInterfaceDef
99  m_EventsHandled.AddEventHandler(eEvent);
100  }
102  {
103  m_EventsHandled.RemoveEventHandler(eEvent);
104  }
105  bool HasEventHandler(EVENTX_TYPE eEvent) const
106  {
107  return m_EventsHandled.HasEventHandler(eEvent);
108  }
109 #if 0
110  void RegisterAllEventHandlers()
111  {
112  // Assume all methods in the interface are desired.
113  return m_EventsHandled.AddAllEventHandlers();
114  }
115 #endif
116 
117  public:
119  CSCRIPT_CLASS_DEF1(XObjEventSink, cXObjDef);
120  enum P_TYPE_
121  {
122 #define cXObjEventSinkProp(a,b,c) P_##a,
123 #include "cXObjEventSinkProps.tbl"
124 #undef cXObjEventSinkProp
126  };
127  static cScriptableProp sm_Props[P_QTY + 1];
128 
129  protected:
132  };
133 
135 };
136 #endif
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define HRESULT_WIN32_C(x)
a constant LSTATUS/error_status_t with no check, unlike HRESULT_FROM_WIN32()
Definition: HResult.h:79
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define CSCRIPT_CLASS_DEF1(TYPE, _BASETYPE)
Definition: cScriptableInterface.h:277
Definition: cScriptContext.h:24
Definition: cScriptableEventsMask.h:34
Definition: cScriptableInterface.h:300
Definition: cScriptableInterface.h:97
Definition: cVariant.h:26
Definition: cXObjDef.h:17
P_TYPE_
Definition: cXObjDef.h:30
Definition: cXObjEventSink.h:49
EVENTPRI_TYPE get_SortValue() const noexcept
Definition: cXObjEventSink.h:72
cScriptableEventsMask m_EventsHandled
What events/methods from my get_EventSinkInterfaceDef do i actually handle?
Definition: cXObjEventSink.h:131
void InitEventHandlers()
Definition: cXObjEventSink.h:91
CHEAPOBJECT_IMPL
Definition: cXObjEventSink.h:118
EVENTPRI_TYPE m_ePriorityLevel
how to sort in cXObjEventSinks
Definition: cXObjEventSink.h:130
void UnregisterEventHandler(EVENTX_TYPE eEvent)
Definition: cXObjEventSink.h:101
@ P_QTY
Definition: cXObjEventSink.h:125
bool HasEventHandler(EVENTX_TYPE eEvent) const
Definition: cXObjEventSink.h:105
static bool IsHandledEvent(EVENTRET_TYPE hRes) noexcept
Definition: cXObjEventSink.h:65
void RegisterEventHandler(EVENTX_TYPE eEvent)
Definition: cXObjEventSink.h:96
virtual const cScriptableInterfaceDef * get_EventSinkInterfaceDef() const =0
Definition: cXObjEventSinks.h:17
Definition: cXObjPackChild.h:18
Definition: cXObjScript.h:28
Definition: cXObject.h:78
Definition: cAtom.h:63
Definition: cRefPtr.h:225
Definition: cMesh.h:22
EVENTPRI_TYPE
Definition: cXObjEventSink.h:21
@ EVENTPRI_MEDIUM
Definition: cXObjEventSink.h:26
@ EVENTPRI_DEFAULT
Process this last.
Definition: cXObjEventSink.h:28
@ EVENTPRI_HIGH
Definition: cXObjEventSink.h:25
@ EVENTPRI_LOW
Definition: cXObjEventSink.h:27
@ EVENTPRI_FIRST
Process this first.
Definition: cXObjEventSink.h:24
cRefPtr< cXObjEventSink > cXObjEventSinkPtr
Definition: cXObjEventSink.h:134
SCRIPTPROPID_t EVENTX_TYPE
a EVENTX_TYPE_
Definition: cScriptableEventsMask.h:29
EVENTRET_TYPE
Definition: cXObjEventSink.h:32
@ EVENTRET_Failed
<0 = script failed to process properly. HRESULT
Definition: cXObjEventSink.h:38
@ EVENTRET_HandledExclusive
3 = eaten by a Handler, blocked from all other Handlers.
Definition: cXObjEventSink.h:44
@ EVENTRET_Handled
0 = handled by Handler. (also do any other default handlers)
Definition: cXObjEventSink.h:40
@ EVENTRET_HandledNoDefault
2 = eaten by Handler. (don't call >= EVENTPRI_DEFAULT handler)
Definition: cXObjEventSink.h:43
@ EVENTRET_NotHandled
1 = not handled by anyone.
Definition: cXObjEventSink.h:41
HASHCODE32_t UID_t
Sort of the same as a HASHCODE_t. not the same as UIDINDEX_t.
Definition: cUID.h:18
char ATOMCHAR_t
the char form (UNICODE or not) for an atom. (for symbolic names)
Definition: StrConst.h:15