Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
5.2 KiB

  1. helper ValueFlow
  2. {
  3. class RawValue
  4. {
  5. // Construction
  6. public:
  7. RawValue()
  8. {
  9. m_dType = DUIV_UNSET;
  10. }
  11. RawValue(const RawValue & rvSrc)
  12. {
  13. // NOTE: This won't work if we have a v-table
  14. CopyMemory(this, &rvSrc, sizeof(RawValue));
  15. }
  16. RawValue & operator=(const RawValue & rvSrc)
  17. {
  18. // NOTE: This won't work if we have a v-table
  19. CopyMemory(this, &rvSrc, sizeof(RawValue));
  20. return *this;
  21. }
  22. // Operations:
  23. inline int
  24. GetType()
  25. {
  26. return m_dType;
  27. }
  28. inline int
  29. GetInt()
  30. {
  31. ASSERT(m_dType == DUIV_INT);
  32. return m_intVal;
  33. }
  34. inline bool
  35. GetBool()
  36. {
  37. ASSERT(m_dType == DUIV_BOOL);
  38. return m_boolVal;
  39. }
  40. inline const POINT*
  41. GetPoint()
  42. {
  43. ASSERT(m_dType == DUIV_POINT);
  44. return &m_ptVal;
  45. }
  46. inline const SIZE*
  47. GetSize()
  48. {
  49. ASSERT(m_dType == DUIV_SIZE);
  50. return &m_sizeVal;
  51. }
  52. inline const RECT*
  53. GetRect()
  54. {
  55. ASSERT(m_dType == DUIV_RECT);
  56. return &m_rectVal;
  57. }
  58. inline const DirectUI::Fill*
  59. GetFill()
  60. {
  61. ASSERT(m_dType == DUIV_FILL);
  62. return &m_fillVal;
  63. }
  64. inline void
  65. SetInt(int val)
  66. {
  67. m_dType = DUIV_INT;
  68. m_intVal = val;
  69. }
  70. inline void
  71. SetBool(bool val)
  72. {
  73. m_dType = DUIV_BOOL;
  74. m_boolVal = val;
  75. }
  76. inline void
  77. SetPoint(int x, int y)
  78. {
  79. m_dType = DUIV_POINT;
  80. m_ptVal.x = x;
  81. m_ptVal.y = y;
  82. }
  83. inline void
  84. SetPoint(const POINT & pt)
  85. {
  86. m_dType = DUIV_POINT;
  87. m_ptVal = pt;
  88. }
  89. inline void
  90. SetSize(int cx, int cy)
  91. {
  92. m_dType = DUIV_SIZE;
  93. m_sizeVal.cx = cx;
  94. m_sizeVal.cy = cy;
  95. }
  96. inline void
  97. SetSize(const SIZE & val)
  98. {
  99. m_dType = DUIV_SIZE;
  100. m_sizeVal = val;
  101. }
  102. inline void
  103. SetRect(int left, int top, int right, int bottom)
  104. {
  105. m_dType = DUIV_RECT;
  106. m_rectVal.left = left;
  107. m_rectVal.top = top;
  108. m_rectVal.right = right;
  109. m_rectVal.bottom = bottom;
  110. }
  111. inline void
  112. SetRect(const RECT & rc)
  113. {
  114. m_dType = DUIV_RECT;
  115. m_rectVal = rc;
  116. }
  117. inline void
  118. SetFill(const DirectUI::Fill & clr)
  119. {
  120. m_dType = DUIV_FILL;
  121. m_fillVal = clr;
  122. }
  123. HRESULT
  124. SetValue(DirectUI::Value * pvSrc)
  125. {
  126. int nNewType = pvSrc->GetType();
  127. switch (nNewType)
  128. {
  129. case DUIV_INT: m_intVal = pvSrc->GetInt(); break;
  130. case DUIV_BOOL: m_boolVal = pvSrc->GetBool(); break;
  131. case DUIV_POINT: m_ptVal = *(pvSrc->GetPoint()); break;
  132. case DUIV_SIZE: m_sizeVal = *(pvSrc->GetSize()); break;
  133. case DUIV_RECT: m_rectVal = *(pvSrc->GetRect()); break;
  134. case DUIV_FILL: m_fillVal = *(pvSrc->GetFill()); break;
  135. default:
  136. ASSERT(0 && "Unknown value type");
  137. return E_INVALIDARG;
  138. }
  139. m_dType = (short) nNewType;
  140. return S_OK;
  141. }
  142. HRESULT
  143. GetValue(DirectUI::Value ** ppvNew)
  144. {
  145. DirectUI::Value * pvNew = NULL;
  146. switch (m_dType)
  147. {
  148. case DUIV_INT: pvNew = DirectUI::Value::CreateInt(m_intVal); break;
  149. case DUIV_BOOL: pvNew = DirectUI::Value::CreateBool(m_boolVal); break;
  150. case DUIV_POINT: pvNew = DirectUI::Value::CreatePoint(m_ptVal.x, m_ptVal.y); break;
  151. case DUIV_SIZE: pvNew = DirectUI::Value::CreateSize(m_sizeVal.cx, m_sizeVal.cy); break;
  152. case DUIV_RECT: pvNew = DirectUI::Value::CreateRect(m_rectVal.left, m_rectVal.top, m_rectVal.right, m_rectVal.bottom); break;
  153. case DUIV_FILL: pvNew = DirectUI::Value::CreateFill(m_fillVal);
  154. default:
  155. ASSERT(0 && "Unknown value type");
  156. return E_INVALIDARG;
  157. }
  158. *ppvNew = pvNew;
  159. return S_OK;
  160. }
  161. // Data
  162. protected:
  163. short m_dType;
  164. union
  165. {
  166. int m_intVal;
  167. bool m_boolVal;
  168. POINT m_ptVal;
  169. SIZE m_sizeVal;
  170. RECT m_rectVal;
  171. DirectUI::Fill
  172. m_fillVal;
  173. };
  174. };
  175. struct ValueFlowCI : public Flow::FlowCI
  176. {
  177. DirectUI::PropertyInfo*
  178. ppi;
  179. };
  180. struct ValueKeyFrame : DUser::KeyFrame
  181. {
  182. DirectUI::PropertyInfo*
  183. ppi;
  184. ValueFlow::RawValue
  185. rv;
  186. };
  187. };