285f24ac3a111ecbab0f002e69a608b76ef8c22b.svn-base 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. using Infragistics.Win.UltraWinTree;
  2. namespace Core.Mes.ClientPurviewManager
  3. {
  4. //Enumerates the possiblt Drop States
  5. [System.Flags] public enum DropLinePositionEnum
  6. {
  7. None = 0,
  8. OnNode = 1,
  9. AboveNode = 2,
  10. BelowNode = 4,
  11. All = OnNode | AboveNode | BelowNode
  12. }
  13. public class UltraTree_DropHightLight_DrawFilter_Class:Infragistics.Win.IUIElementDrawFilter
  14. {
  15. //This class has to implement the DrawFilter Interface
  16. //so it can be used as a DrawFilter by the tree
  17. public event System.EventHandler Invalidate;
  18. //public delegate void InvalidateEventHandler( object sender, EventArgs e );
  19. public event QueryStateAllowedForNodeEventHandler QueryStateAllowedForNode;
  20. public delegate void QueryStateAllowedForNodeEventHandler( object sender, QueryStateAllowedForNodeEventArgs e );
  21. //Used by the QueryStateAllowedForNode event
  22. public class QueryStateAllowedForNodeEventArgs:System.EventArgs
  23. {
  24. public UltraTreeNode Node ;
  25. public DropLinePositionEnum DropLinePosition;
  26. public DropLinePositionEnum StatesAllowed ;
  27. }
  28. public UltraTree_DropHightLight_DrawFilter_Class()
  29. {
  30. //Initialize the properties to the defaults
  31. InitProperties();
  32. }
  33. //Initialize the properties to the defaults
  34. private void InitProperties()
  35. {
  36. mvarDropHighLightNode = null;
  37. mvarDropLinePosition = DropLinePositionEnum.None;
  38. mvarDropHighLightBackColor = System.Drawing.SystemColors.Highlight;
  39. mvarDropHighLightForeColor = System.Drawing.SystemColors.HighlightText;
  40. mvarDropLineColor = System.Drawing.SystemColors.ControlText;
  41. mvarEdgeSensitivity = 0;
  42. mvarDropLineWidth = 2;
  43. }
  44. //Clean up
  45. public void Dispose()
  46. {
  47. mvarDropHighLightNode = null;
  48. }
  49. //The DropHighLightNode is a reference to the node the
  50. //Mouse is currently over
  51. private UltraTreeNode mvarDropHighLightNode;
  52. public UltraTreeNode DropHightLightNode
  53. {
  54. get
  55. {
  56. return mvarDropHighLightNode;
  57. }
  58. set
  59. {
  60. //If the Node is being set to the same value,
  61. // just exit
  62. if (mvarDropHighLightNode.Equals(value))
  63. {
  64. return;
  65. }
  66. mvarDropHighLightNode = value;
  67. //The DropNode has changed.
  68. PositionChanged();
  69. }
  70. }
  71. private DropLinePositionEnum mvarDropLinePosition;
  72. public DropLinePositionEnum DropLinePosition
  73. {
  74. get
  75. {
  76. return mvarDropLinePosition;
  77. }
  78. set
  79. {
  80. //If the position is the same as it was,
  81. //just exit
  82. if (mvarDropLinePosition == value)
  83. {
  84. return;
  85. }
  86. mvarDropLinePosition = value;
  87. //The Drop Position has changed
  88. PositionChanged();
  89. }
  90. }
  91. //The width of the DropLine
  92. private int mvarDropLineWidth;
  93. public int DropLineWidth
  94. {
  95. get
  96. {
  97. return mvarDropLineWidth;
  98. }
  99. set
  100. {
  101. mvarDropLineWidth = value;
  102. }
  103. }
  104. //The BackColor of the DropHighLight node
  105. //This only affect the node when it is being dropped On.
  106. //Not Above or Below.
  107. private System.Drawing.Color mvarDropHighLightBackColor;
  108. public System.Drawing.Color DropHighLightBackColor
  109. {
  110. get
  111. {
  112. return mvarDropHighLightBackColor;
  113. }
  114. set
  115. {
  116. mvarDropHighLightBackColor = value;
  117. }
  118. }
  119. //The ForeColor of the DropHighLight node
  120. //This only affect the node when it is being dropped On.
  121. //Not Above or Below.
  122. private System.Drawing.Color mvarDropHighLightForeColor;
  123. public System.Drawing.Color DropHighLightForeColor
  124. {
  125. get
  126. {
  127. return mvarDropHighLightForeColor;
  128. }
  129. set
  130. {
  131. mvarDropHighLightForeColor = value;
  132. }
  133. }
  134. //The color of the DropLine
  135. private System.Drawing.Color mvarDropLineColor ;
  136. public System.Drawing.Color DropLineColor
  137. {
  138. get
  139. {
  140. return mvarDropLineColor;
  141. }
  142. set
  143. {
  144. mvarDropLineColor = value;
  145. }
  146. }
  147. //Determines how close to the top or bottom edge of a node
  148. //the mouse must be to be consider dropping Above or Below
  149. //respectively.
  150. //By default the top 1/3 of the node is Above, the bottom 1/3
  151. //is Below, and the middle is On.
  152. private int mvarEdgeSensitivity ;
  153. public int EdgeSensitivity
  154. {
  155. get
  156. {
  157. return mvarEdgeSensitivity;
  158. }
  159. set
  160. {
  161. mvarEdgeSensitivity = value;
  162. }
  163. }
  164. //When the DropNode or DropPosition change, we fire the
  165. //Invalidate event to let the program know to invalidate
  166. //the Tree control.
  167. //This is neccessary since the DrawFilter does not have a
  168. //reference to the Tree Control (although it probably could)
  169. private void PositionChanged()
  170. {
  171. // if nobody is listening then just return
  172. //
  173. if ( null == this.Invalidate)
  174. return;
  175. System.EventArgs e = System.EventArgs.Empty;
  176. this.Invalidate(this, e);
  177. }
  178. //Set the DropNode to Nothing and the position to None. This
  179. //Will clear whatever Drophighlight is in the tree
  180. public void ClearDropHighlight()
  181. {
  182. SetDropHighlightNode(null, DropLinePositionEnum.None);
  183. }
  184. //Call this proc every time the DragOver event of the
  185. //Tree fires.
  186. //Note that the point pass in MUST be in Tree coords, not
  187. //form coords
  188. public void SetDropHighlightNode(UltraTreeNode Node, System.Drawing.Point PointInTreeCoords )
  189. {
  190. //The distance from the edge of the node used to
  191. //determine whether to drop Above, Below, or On a node
  192. int DistanceFromEdge;
  193. //The new DropLinePosition
  194. DropLinePositionEnum NewDropLinePosition;
  195. DistanceFromEdge = mvarEdgeSensitivity;
  196. //Check to see if DistanceFromEdge is 0
  197. if (DistanceFromEdge == 0)
  198. {
  199. //It is, so we use the default value - one third.
  200. DistanceFromEdge = Node.Bounds.Height / 3;
  201. }
  202. //Determine which part of the node the point is in
  203. if (PointInTreeCoords.Y < (Node.Bounds.Top + DistanceFromEdge))
  204. {
  205. //Point is in the top of the node
  206. NewDropLinePosition = DropLinePositionEnum.AboveNode;
  207. }
  208. else
  209. {
  210. if (PointInTreeCoords.Y > ((Node.Bounds.Bottom - DistanceFromEdge) - 1))
  211. {
  212. //Point is in the bottom of the node
  213. NewDropLinePosition = DropLinePositionEnum.BelowNode;
  214. }
  215. else
  216. {
  217. //Point is in the middle of the node
  218. NewDropLinePosition = DropLinePositionEnum.OnNode;
  219. }
  220. }
  221. //Now that we have the new DropLinePosition, call the
  222. //real proc to get things rolling
  223. SetDropHighlightNode(Node, NewDropLinePosition);
  224. }
  225. private void SetDropHighlightNode(UltraTreeNode Node , DropLinePositionEnum DropLinePosition )
  226. {
  227. //Use to store whether there have been any changes in
  228. //DropNode or DropLinePosition
  229. bool IsPositionChanged = false;
  230. try
  231. {
  232. //Check to see if the nodes are equal and if
  233. //the dropline position are equal
  234. if (mvarDropHighLightNode != null && mvarDropHighLightNode.Equals(Node) && (mvarDropLinePosition == DropLinePosition))
  235. {
  236. //They are both equal. Nothing has changed.
  237. IsPositionChanged = false;
  238. }
  239. else
  240. {
  241. //One or both have changed
  242. IsPositionChanged = true;
  243. }
  244. }
  245. catch
  246. {
  247. //If we reach this code, it means mvarDropHighLightNode
  248. //is null, so it could not be compared
  249. if (mvarDropHighLightNode == null)
  250. {
  251. //Check to see if Node is nothing, so we//ll know
  252. //if Node = mvarDropHighLightNode
  253. IsPositionChanged = !(Node == null);
  254. }
  255. }
  256. //Set both properties without calling PositionChanged
  257. mvarDropHighLightNode = Node;
  258. mvarDropLinePosition = DropLinePosition;
  259. //Check to see if the PositionChanged
  260. if (IsPositionChanged)
  261. {
  262. //Position did change.
  263. PositionChanged();
  264. }
  265. }
  266. //Only need to trap for 2 phases:
  267. //AfterDrawElement: for drawing the DropLine
  268. //BeforeDrawElement: for drawing the DropHighlight
  269. Infragistics.Win.DrawPhase Infragistics.Win.IUIElementDrawFilter.GetPhasesToFilter(ref Infragistics.Win.UIElementDrawParams drawParams)
  270. {
  271. return Infragistics.Win.DrawPhase.AfterDrawElement | Infragistics.Win.DrawPhase.BeforeDrawElement;
  272. }
  273. //The actual drawing code
  274. bool Infragistics.Win.IUIElementDrawFilter.DrawElement(Infragistics.Win.DrawPhase drawPhase, ref Infragistics.Win.UIElementDrawParams drawParams)
  275. {
  276. Infragistics.Win.UIElement aUIElement;
  277. System.Drawing.Graphics g;
  278. UltraTreeNode aNode;
  279. //If there//s no DropHighlight node or no position
  280. //specified, then we don//t need to draw anything special.
  281. //Just exit Function
  282. if ((mvarDropHighLightNode == null) || (mvarDropLinePosition == DropLinePositionEnum.None))
  283. {
  284. return false;
  285. }
  286. //Create a new QueryStateAllowedForNodeEventArgs object
  287. //to pass to the event
  288. QueryStateAllowedForNodeEventArgs eArgs = new QueryStateAllowedForNodeEventArgs();
  289. //Initialize the object with the correct info
  290. eArgs.Node = mvarDropHighLightNode;
  291. eArgs.DropLinePosition = this.mvarDropLinePosition;
  292. //Default to all states allowed.
  293. eArgs.StatesAllowed = DropLinePositionEnum.All;
  294. //Raise the event
  295. this.QueryStateAllowedForNode(this, eArgs);
  296. //Check to see if the user allowed the current state
  297. //for this node. If not, exit function
  298. if ((eArgs.StatesAllowed & mvarDropLinePosition) != mvarDropLinePosition)
  299. {
  300. return false;
  301. }
  302. //Get the element being drawn
  303. aUIElement = drawParams.Element;
  304. //Determine which drawing phase we are in.
  305. switch (drawPhase)
  306. {
  307. case Infragistics.Win.DrawPhase.BeforeDrawElement:
  308. {
  309. //We are in BeforeDrawElement, so we are only concerned with
  310. //drawing the OnNode state.
  311. if ((mvarDropLinePosition & DropLinePositionEnum.OnNode) == DropLinePositionEnum.OnNode)
  312. {
  313. //Check to see if we are drawing a NodeTextUIElement
  314. if (aUIElement.GetType() == typeof(Infragistics.Win.UltraWinTree.NodeTextUIElement))
  315. {
  316. //Get a reference to the node that this
  317. //NodeTextUIElement is associated with
  318. aNode = (UltraTreeNode)aUIElement.GetContext(typeof(UltraTreeNode));
  319. //See if this is the DropHighlightNode
  320. if (aNode.Equals(mvarDropHighLightNode))
  321. {
  322. //Set the ForeColor and Backcolor of the node
  323. //to the DropHighlight colors
  324. //Note that AppearanceData only affects the
  325. //node for this one paint. It will not
  326. //change any properties of the node
  327. drawParams.AppearanceData.BackColor = mvarDropHighLightBackColor;
  328. drawParams.AppearanceData.ForeColor = mvarDropHighLightForeColor;
  329. }
  330. }
  331. }
  332. break;
  333. }
  334. case Infragistics.Win.DrawPhase.AfterDrawElement:
  335. {
  336. //We're in AfterDrawElement
  337. //So the only states we are conderned with are
  338. //Below and Above
  339. //Check to see if we are drawing the Tree Element
  340. if (aUIElement.GetType() == typeof(Infragistics.Win.UltraWinTree.UltraTreeUIElement))
  341. {
  342. //Declare a pen to us for drawing Droplines
  343. System.Drawing.Pen p = new System.Drawing.Pen(mvarDropLineColor, mvarDropLineWidth);
  344. //Get a reference to the Graphics object
  345. //we are drawing to.
  346. g = drawParams.Graphics;
  347. //Get the NodeSelectableAreaUIElement for the
  348. //current DropNode. We will use this for
  349. //positioning and sizing the DropLine
  350. Infragistics.Win.UltraWinTree.NodeSelectableAreaUIElement tElement ;
  351. tElement = (Infragistics.Win.UltraWinTree.NodeSelectableAreaUIElement)drawParams.Element.GetDescendant(typeof(Infragistics.Win.UltraWinTree.NodeSelectableAreaUIElement), mvarDropHighLightNode);
  352. //The left edge of the DropLine
  353. int LeftEdge = tElement.Rect.Left - 4;
  354. //We need a reference to the control to
  355. //determine the right edge of the line
  356. UltraTree aTree;
  357. aTree = (UltraTree)tElement.GetContext(typeof(UltraTree));
  358. int RightEdge = aTree.DisplayRectangle.Right -4;
  359. //Used to store the Vertical position of the
  360. //DropLine
  361. int LineVPosition;
  362. if ((mvarDropLinePosition & DropLinePositionEnum.AboveNode) == DropLinePositionEnum.AboveNode)
  363. {
  364. //Draw line above node
  365. LineVPosition = mvarDropHighLightNode.Bounds.Top;
  366. g.DrawLine(p, LeftEdge, LineVPosition, RightEdge, LineVPosition);
  367. p.Width = 1;
  368. g.DrawLine(p, LeftEdge, LineVPosition - 3, LeftEdge, LineVPosition + 2);
  369. g.DrawLine(p, LeftEdge + 1, LineVPosition - 2, LeftEdge + 1, LineVPosition + 1);
  370. g.DrawLine(p, RightEdge, LineVPosition - 3, RightEdge, LineVPosition + 2);
  371. g.DrawLine(p, RightEdge - 1, LineVPosition - 2, RightEdge - 1, LineVPosition + 1);
  372. }
  373. if ((mvarDropLinePosition & DropLinePositionEnum.BelowNode) == DropLinePositionEnum.BelowNode)
  374. {
  375. //Draw Line below node
  376. LineVPosition = mvarDropHighLightNode.Bounds.Bottom;
  377. g.DrawLine(p, LeftEdge, LineVPosition, RightEdge, LineVPosition);
  378. p.Width = 1;
  379. g.DrawLine(p, LeftEdge, LineVPosition - 3, LeftEdge, LineVPosition + 2);
  380. g.DrawLine(p, LeftEdge + 1, LineVPosition - 2, LeftEdge + 1, LineVPosition + 1);
  381. g.DrawLine(p, RightEdge, LineVPosition - 3, RightEdge, LineVPosition + 2);
  382. g.DrawLine(p, RightEdge - 1, LineVPosition - 2, RightEdge - 1, LineVPosition + 1);
  383. }
  384. }
  385. break;
  386. }
  387. }
  388. return false;
  389. }
  390. }
  391. }