Leaked source code of windows server 2003
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.

497 lines
9.0 KiB

  1. enum NodeType
  2. {
  3. DataNode = 0,
  4. AndNode = 1,
  5. OrNode = 2,
  6. XorNode = 3
  7. };
  8. // shape flags for temporary editing
  9. #define ShapeDisabled 0x00000001
  10. template <class Data> class TreeNode
  11. {
  12. public:
  13. friend class TestShapeRegion;
  14. TreeNode(NodeType type = DataNode, Data* data = NULL, BOOL notNode = FALSE)
  15. {
  16. this->type = type;
  17. this->data = data;
  18. this->notNode = notNode;
  19. nodeName = NULL;
  20. if (data)
  21. {
  22. // !! violates we are a template class.. Yipes!! hacky!!
  23. path = new GraphicsPath();
  24. data->AddToPath(path);
  25. }
  26. else
  27. path = NULL;
  28. nextSibling = NULL;
  29. prevSibling = NULL;
  30. parent = NULL;
  31. firstChild = NULL;
  32. hItem = (HTREEITEM)-1;
  33. }
  34. ~TreeNode()
  35. {
  36. if (nodeName)
  37. free(nodeName);
  38. TreeNode* next = firstChild;
  39. while (next)
  40. {
  41. TreeNode* nextnext = next->nextSibling;
  42. delete next;
  43. next = nextnext;
  44. }
  45. if (nextSibling)
  46. nextSibling->prevSibling = prevSibling;
  47. if (prevSibling)
  48. prevSibling->nextSibling = nextSibling;
  49. if (parent && parent->firstChild == this)
  50. parent->firstChild = nextSibling;
  51. if (path)
  52. delete path;
  53. };
  54. TreeNode* GetRoot()
  55. {
  56. TreeNode* next = parent;
  57. while (next && next->parent)
  58. next = next->parent;
  59. return next ? next : this;
  60. }
  61. BOOL HasChildren()
  62. {
  63. return (firstChild) ? TRUE : FALSE;
  64. }
  65. TreeNode* GetParent()
  66. {
  67. return parent;
  68. }
  69. TreeNode* GetNextSibling()
  70. {
  71. return nextSibling;
  72. }
  73. TreeNode* GetPrevSibling()
  74. {
  75. return prevSibling;
  76. }
  77. TreeNode* GetFirstChild()
  78. {
  79. return firstChild;
  80. }
  81. VOID MoveChildrenToParent()
  82. {
  83. ASSERT(parent);
  84. TreeNode* lastSibling = parent->firstChild;
  85. while (lastSibling->nextSibling)
  86. lastSibling = lastSibling->nextSibling;
  87. lastSibling->nextSibling = firstChild;
  88. if (firstChild)
  89. firstChild->prevSibling = lastSibling;
  90. lastSibling = firstChild;
  91. while (lastSibling)
  92. {
  93. lastSibling->parent = parent;
  94. lastSibling = lastSibling->nextSibling;
  95. }
  96. firstChild = NULL;
  97. }
  98. HTREEITEM CreateTreeView(HWND hwndTV)
  99. {
  100. HTREEITEM hTreeItem = AddToTreeView(hwndTV);
  101. if (nextSibling)
  102. nextSibling->CreateTreeView(hwndTV);
  103. if (firstChild)
  104. firstChild->CreateTreeView(hwndTV);
  105. return hTreeItem;
  106. }
  107. HTREEITEM AddToTreeView(HWND hwndTV)
  108. {
  109. nodeName = GetNodeName(type, notNode, data);
  110. TVINSERTSTRUCT insertStruct =
  111. {
  112. parent ? (HTREEITEM)parent->GetHTREEITEM() : TVI_ROOT,
  113. prevSibling ? (HTREEITEM)prevSibling->GetHTREEITEM() : TVI_FIRST,
  114. };
  115. TVITEMEX itemex =
  116. {
  117. TVIF_CHILDREN|
  118. TVIF_PARAM|
  119. TVIF_STATE|
  120. TVIF_TEXT, // mask
  121. (HTREEITEM)(NULL), // identifies TV item
  122. 0, // state
  123. 0, // stateMask
  124. nodeName, // text to display
  125. 0, // cchTextMax
  126. 0, // iImage
  127. 0, // iSelectedImage
  128. (firstChild ? 1 : 0), // cChildren
  129. (LPARAM)(this), // lParam
  130. 1 // iIntegral
  131. };
  132. // !! wasn't able to compile into one assignment !?!?
  133. insertStruct.itemex = itemex;
  134. hItem = TreeView_InsertItem(hwndTV, &insertStruct);
  135. return hItem;
  136. };
  137. VOID AddChild(TreeNode* node)
  138. {
  139. if (!firstChild)
  140. {
  141. firstChild = node;
  142. node->parent = this;
  143. node->prevSibling = NULL;
  144. node->nextSibling = NULL;
  145. node->firstChild = NULL;
  146. }
  147. else
  148. {
  149. TreeNode* next = firstChild;
  150. while (next->nextSibling)
  151. next = next->nextSibling;
  152. next->nextSibling = node;
  153. node->parent = this;
  154. node->prevSibling = next;
  155. node->nextSibling = NULL;
  156. node->firstChild = NULL;
  157. }
  158. };
  159. VOID AddSibling(TreeNode* node)
  160. {
  161. TreeNode* next = this;
  162. while (next->nextSibling)
  163. next = next->nextSibling;
  164. if (next)
  165. {
  166. next->nextSibling = node;
  167. node->parent = this->parent;
  168. node->prevSibling = next;
  169. node->nextSibling = NULL;
  170. node->firstChild = NULL;
  171. }
  172. else
  173. ASSERT(FALSE);
  174. };
  175. VOID AddAsParent(TreeNode* newParent)
  176. {
  177. newParent->parent = parent;
  178. newParent->prevSibling = prevSibling;
  179. newParent->nextSibling = nextSibling;
  180. newParent->firstChild = this;
  181. if (parent && parent->firstChild == this)
  182. parent->firstChild = newParent;
  183. if (prevSibling)
  184. prevSibling->nextSibling = newParent;
  185. if (nextSibling)
  186. nextSibling->prevSibling = newParent;
  187. nextSibling = NULL;
  188. prevSibling = NULL;
  189. parent = newParent;
  190. }
  191. BOOL IsEmpty()
  192. {
  193. return (type == DataNode) && (notNode) && (data == NULL);
  194. }
  195. BOOL IsInfinite()
  196. {
  197. return (type == DataNode) && (!notNode) && (data == NULL);
  198. }
  199. HTREEITEM GetHTREEITEM()
  200. {
  201. return hItem;
  202. }
  203. static LPTSTR GetNodeName(NodeType type,
  204. BOOL notNode,
  205. Data* data)
  206. {
  207. TCHAR tmpName[MAX_PATH];
  208. LPTSTR name;
  209. switch(type)
  210. {
  211. case DataNode:
  212. // !! won't work on other template class types.
  213. if (data)
  214. {
  215. if (notNode)
  216. {
  217. name = &tmpName[0];
  218. _stprintf(&tmpName[0],
  219. _T("NOT %s"),
  220. data->GetShapeName());
  221. }
  222. else
  223. name = data->GetShapeName();
  224. }
  225. else
  226. {
  227. if (notNode)
  228. name = _T("Empty");
  229. else
  230. name = _T("Infinite");
  231. }
  232. break;
  233. case AndNode:
  234. if (notNode)
  235. name = _T("NAND");
  236. else
  237. name = _T("AND");
  238. break;
  239. case OrNode:
  240. if (notNode)
  241. name = _T("NOR");
  242. else
  243. name = _T("OR");
  244. break;
  245. case XorNode:
  246. if (notNode)
  247. name = _T("NXOR");
  248. else
  249. name = _T("XOR");
  250. break;
  251. default:
  252. ASSERT(FALSE);
  253. return _T("Unknown!?!");
  254. };
  255. return _tcsdup(name);
  256. }
  257. Region* GetRegion()
  258. {
  259. Region* newRegion = NULL;
  260. switch(type)
  261. {
  262. case DataNode:
  263. {
  264. if (path)
  265. newRegion = new Region(path);
  266. else
  267. {
  268. newRegion = new Region();
  269. newRegion->SetInfinite();
  270. }
  271. break;
  272. }
  273. case AndNode:
  274. case OrNode:
  275. case XorNode:
  276. {
  277. Region* curRegion;
  278. TreeNode* curNode = firstChild;
  279. newRegion = new Region();
  280. if (type == AndNode)
  281. newRegion->SetInfinite();
  282. else
  283. newRegion->SetEmpty();
  284. while (curNode)
  285. {
  286. curRegion = curNode->GetRegion();
  287. if (type == AndNode)
  288. newRegion->And(curRegion);
  289. else if (type == OrNode)
  290. newRegion->Or(curRegion);
  291. else
  292. {
  293. ASSERT(type == XorNode);
  294. newRegion->Xor(curRegion);
  295. }
  296. curNode = curNode->nextSibling;
  297. delete curRegion;
  298. }
  299. break;
  300. }
  301. default:
  302. ASSERT(FALSE);
  303. break;
  304. }
  305. // complement the current region
  306. if (notNode)
  307. {
  308. Region *tmpRegion = new Region();
  309. tmpRegion->SetInfinite();
  310. newRegion->Complement(tmpRegion);
  311. delete tmpRegion;
  312. }
  313. return newRegion;
  314. }
  315. TreeNode* Clone()
  316. {
  317. TreeNode* newNode = new TreeNode(type, data, notNode);
  318. TreeNode* curNode = firstChild;
  319. TreeNode* newSibling = NULL;
  320. // loop through all children, clone and add to 'newNode'
  321. while (curNode)
  322. {
  323. TreeNode *newChild = curNode->Clone();
  324. newChild->nodeName = GetNodeName(type, notNode, data);
  325. if (!newSibling)
  326. newSibling = newNode->firstChild = newChild;
  327. else
  328. {
  329. newSibling->nextSibling = newChild;
  330. newChild->prevSibling = newSibling;
  331. newSibling = newChild;
  332. }
  333. newChild->parent = newNode;
  334. curNode = curNode->nextSibling;
  335. }
  336. return newNode;
  337. }
  338. private:
  339. NodeType type;
  340. BOOL notNode;
  341. LPTSTR nodeName;
  342. TreeNode* nextSibling;
  343. TreeNode* prevSibling;
  344. TreeNode* firstChild;
  345. TreeNode* parent;
  346. HTREEITEM hItem;
  347. GraphicsPath* path; // GDI+ path for shape
  348. Data* data;
  349. };
  350. typedef TreeNode<TestShape> ClipTree;
  351. class TestShapeRegion : public TestConfigureInterface,
  352. public TestDialogInterface
  353. {
  354. public:
  355. TestShapeRegion()
  356. {
  357. clipTree = new ClipTree(AndNode, NULL, FALSE);
  358. origTree = NULL;
  359. shapeStack = new ShapeStack();
  360. origStack = NULL;
  361. }
  362. ~TestShapeRegion()
  363. {
  364. delete clipTree;
  365. delete shapeStack;
  366. // do not delete 'origTree' or 'origStack'
  367. // these are temporary references for saving under 'OK'
  368. }
  369. // configuration management
  370. virtual BOOL ChangeSettings(HWND hwnd);
  371. virtual VOID Initialize();
  372. virtual VOID Initialize(ShapeStack* stack, TestShape* current, BOOL useClip);
  373. // dialog control interface methods
  374. virtual VOID InitDialog(HWND hwnd);
  375. virtual BOOL SaveValues(HWND hwnd);
  376. virtual BOOL ProcessDialog(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  377. Region* GetClipRegion();
  378. BOOL GetClipBool()
  379. {
  380. return origUseClip;
  381. }
  382. protected:
  383. VOID AddClipNode(HWND hwnd, NodeType type = DataNode);
  384. VOID RemoveClipNode(HWND hwnd);
  385. VOID ToggleNotNode(HWND hwnd);
  386. VOID ShiftCurrentShape(HWND hwnd, INT dir);
  387. VOID ToggleDisableShape(HWND hwnd);
  388. VOID UpdateShapePicture(HWND hwnd);
  389. VOID CleanUpPictures(HWND hwnd);
  390. private:
  391. // currently modified parameters
  392. ShapeStack* shapeStack;
  393. ClipTree* clipTree;
  394. // original saved parameters
  395. ShapeStack* origStack;
  396. ClipTree* origTree;
  397. BOOL origUseClip;
  398. };