ChartToolTip.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. using Microsoft.VisualBasic.CompilerServices;
  2. using MuchInfo.Chart.Data.Interfaces;
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. using System.Threading;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Controls.Primitives;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. namespace MuchInfo.Chart.Infrastructure.Helpers
  12. {
  13. public class ChartToolTip
  14. {
  15. //#region Fields
  16. //private static Border border;
  17. //private static object monitorObject = RuntimeHelpers.GetObjectValue(new object());
  18. //private static Popup popupDialog;
  19. //private static TextBlock textBlock;
  20. //private static ToolTipContent ToolTipContent;
  21. //private static Thread wbiToolTip_626;
  22. //#endregion Fields
  23. //#region Properties
  24. //#region Private Static Properties
  25. //private static Border Border
  26. //{
  27. // get
  28. // {
  29. // return border;
  30. // }
  31. // set
  32. // {
  33. // var sizeChangedEventHandler = new SizeChangedEventHandler(OnBorderSizeChanged);
  34. // if (border != null)
  35. // {
  36. // border.SizeChanged -= sizeChangedEventHandler;
  37. // }
  38. // border = value;
  39. // if (border != null)
  40. // {
  41. // border.SizeChanged += (sizeChangedEventHandler);
  42. // }
  43. // }
  44. //}
  45. //#endregion Private Static Properties
  46. //#endregion Properties
  47. //#region Methods
  48. //#region Public Static Methods
  49. ////public static void ShowTip(UIElement aCtrl, MouseEventArgs e, string txt, Panel rootPanel)
  50. ////{
  51. //// object obj = monitorObject;
  52. //// ObjectFlowControl.CheckForSyncLockOnValueType(obj);
  53. //// Monitor.Enter(obj);
  54. //// try
  55. //// {
  56. //// bool flag = ToolTipContent == null || !ToolTipContent.UIElement.Equals(aCtrl);
  57. //// if (flag)
  58. //// {
  59. //// Clean(rootPanel);
  60. //// }
  61. //// flag = (ToolTipContent != null);
  62. //// if (flag)
  63. //// {
  64. //// ToolTipContent.Flag = true;
  65. //// }
  66. //// ToolTipContent = new ToolTipContent
  67. //// {
  68. //// Point = e.GetPosition(rootPanel),
  69. //// Title = txt,
  70. //// UIElement = aCtrl
  71. //// };
  72. //// flag = (wbiToolTip_626 == null);
  73. //// if (flag)
  74. //// {
  75. //// wbiToolTip_626 = new Thread(new ThreadStart(wbiToolTip_1677)) {IsBackground = (true)};
  76. //// wbiToolTip_626.Start();
  77. //// }
  78. //// }
  79. //// finally
  80. //// {
  81. //// Monitor.Exit(obj);
  82. //// }
  83. ////}
  84. //public static void ShowTip(UIElement control, MouseEventArgs args, IToolTipControlProvider controlProvider, Panel rootPanel)
  85. //{
  86. // object obj = ChartToolTip.monitorObject;
  87. // //ObjectFlowControl.CheckForSyncLockOnValueType(obj);
  88. // Monitor.Enter(obj);
  89. // try
  90. // {
  91. // if (ToolTipContent == null || ToolTipContent.UIElement != control)
  92. // {
  93. // Clean(rootPanel);
  94. // }
  95. // if (ToolTipContent != null)
  96. // {
  97. // ToolTipContent.Flag = true;
  98. // }
  99. // ToolTipContent = new ToolTipContent
  100. // {
  101. // Point = args.GetPosition(rootPanel),
  102. // ControlProvider = controlProvider,
  103. // UIElement = control
  104. // };
  105. // if (wbiToolTip_626 == null)
  106. // {
  107. // wbiToolTip_626 = new Thread(new ThreadStart(CreateToolTipThread));
  108. // wbiToolTip_626.IsBackground = (true);
  109. // wbiToolTip_626.Start();
  110. // }
  111. // }
  112. // finally
  113. // {
  114. // Monitor.Exit(obj);
  115. // }
  116. //}
  117. //public static void HideTip(UIElement aCtrl, Panel rootPanel)
  118. //{
  119. // try
  120. // {
  121. // object obj = monitorObject;
  122. // ObjectFlowControl.CheckForSyncLockOnValueType(obj);
  123. // Monitor.Enter(obj);
  124. // try
  125. // {
  126. // bool flag = ToolTipContent != null && ToolTipContent.UIElement == aCtrl;
  127. // if (flag)
  128. // {
  129. // ToolTipContent.Flag = true;
  130. // ToolTipContent = null;
  131. // Clean(rootPanel);
  132. // }
  133. // }
  134. // finally
  135. // {
  136. // Monitor.Exit(obj);
  137. // }
  138. // }
  139. // catch (Exception expr_7D)
  140. // {
  141. // ProjectData.SetProjectError(expr_7D);
  142. // ProjectData.ClearProjectError();
  143. // }
  144. //}
  145. //private static void Clean(Panel rootPanel)
  146. //{
  147. // if (popupDialog != null)
  148. // {
  149. // rootPanel.Children.Remove(popupDialog);
  150. // popupDialog = null;
  151. // border = null;
  152. // textBlock = null;
  153. // }
  154. //}
  155. ////private static void wbiToolTip_1677()
  156. ////{
  157. //// while (true)
  158. //// {
  159. //// try
  160. //// {
  161. //// Thread.Sleep(100);
  162. //// PopupManager.PopupRoot.Dispatcher.BeginInvoke(new Action(CreateToolTip));
  163. //// }
  164. //// catch (Exception expr_4E)
  165. //// {
  166. //// ProjectData.SetProjectError(expr_4E);
  167. //// ProjectData.ClearProjectError();
  168. //// }
  169. //// }
  170. ////}
  171. //#endregion Public Static Methods
  172. //#region Private Static Methods
  173. //private static void CreatePopUp()
  174. //{
  175. // //object obj = monitorObject;
  176. // //ObjectFlowControl.CheckForSyncLockOnValueType(obj);
  177. // ////Monitor.Enter(obj);
  178. // //try
  179. // //{
  180. // popupDialog = new Popup();
  181. // popupDialog.Visibility = Visibility.Hidden;
  182. // popupDialog.Name = "ToolTip_Pop";
  183. // PopupManager.PopupRoot.Children.Add(popupDialog);
  184. // var border = new Border();
  185. // border.BorderBrush = (new SolidColorBrush(Colors.Black));
  186. // border.BorderThickness = new Thickness(1.0);
  187. // border.Padding = new Thickness(3.0);
  188. // border.Background = new SolidColorBrush(Colors.LightGray);
  189. // popupDialog.Child = border;
  190. // textBlock = new TextBlock();
  191. // border.Child = textBlock;
  192. // Border = border;
  193. // //}
  194. // //finally
  195. // //{
  196. // // Monitor.Exit(obj);
  197. // //}
  198. //}
  199. //private static void CreateToolTip()
  200. //{
  201. // //object obj = monitorObject;
  202. // ////ObjectFlowControl.CheckForSyncLockOnValueType(obj);
  203. // //try
  204. // //{
  205. // // Monitor.Enter(obj);
  206. // if (ToolTipContent != null && DateTime.Compare(ToolTipContent.Date, DateTime.Now) < 0 && popupDialog == null)
  207. // {
  208. // if (popupDialog == null)
  209. // {
  210. // CreatePopUp();
  211. // }
  212. // if (ToolTipContent.ControlProvider != null)
  213. // {
  214. // Border.BorderBrush = (null);
  215. // Thickness thickness = new Thickness();
  216. // Border.BorderThickness = (thickness);
  217. // Border.Padding = (thickness);
  218. // Border.Background = (null);
  219. // Border.Child = ((UIElement)ToolTipContent.ControlProvider.GetControl());
  220. // }
  221. // else
  222. // {
  223. // Border.BorderBrush = (new SolidColorBrush(Colors.Black));
  224. // Border.BorderThickness = new Thickness(1.0);
  225. // Border.Padding = new Thickness(3.0);
  226. // Border.Background = (new SolidColorBrush(Colors.LightGray));
  227. // Border.Child = textBlock;
  228. // textBlock.Text = ToolTipContent.Title;
  229. // }
  230. // popupDialog.HorizontalOffset = ToolTipContent.Point.X + 12.0;
  231. // popupDialog.VerticalOffset = ToolTipContent.Point.Y + 12.0;
  232. // popupDialog.Visibility = Visibility.Visible;
  233. // popupDialog.IsOpen = true;
  234. // textBlock.UpdateLayout();
  235. // GeometryHelper.EnsureControlInApplication(popupDialog);
  236. // }
  237. // else
  238. // {
  239. // if (popupDialog != null && ToolTipContent != null && popupDialog.IsOpen && DateTime.Compare(ToolTipContent.Date.AddSeconds(5.0), DateTime.Now) < 0)
  240. // {
  241. // ToolTipContent = null;
  242. // Clean();
  243. // }
  244. // else
  245. // {
  246. // if (popupDialog != null && popupDialog.IsOpen && ToolTipContent == null)
  247. // {
  248. // Clean();
  249. // }
  250. // }
  251. // }
  252. // //}
  253. // //finally
  254. // //{
  255. // // Monitor.Exit(obj);
  256. // //}
  257. //}
  258. ////private static void CreateToolTipThread()
  259. ////{
  260. //// while (true)
  261. //// {
  262. //// try
  263. //// {
  264. //// Thread.Sleep(100);
  265. //// PopupManager.PopupRoot.Dispatcher.BeginInvoke(new Action(CreateToolTip));
  266. //// }
  267. //// catch
  268. //// {
  269. //// }
  270. //// }
  271. ////}
  272. //private static void OnBorderSizeChanged(object sender, SizeChangedEventArgs e)
  273. //{
  274. // try
  275. // {
  276. // GeometryHelper.EnsureControlInApplication(popupDialog);
  277. // }
  278. // catch (Exception ex)
  279. // {
  280. // throw ex;
  281. // }
  282. //}
  283. //#endregion Private Static Methods
  284. //#endregion Methods
  285. }
  286. internal class ToolTipContent
  287. {
  288. #region Constructors
  289. public ToolTipContent()
  290. {
  291. this.Date = DateTime.Now.AddSeconds(0.6);
  292. this.Flag = false;
  293. }
  294. #endregion Constructors
  295. #region Properties
  296. #region Public Properties
  297. public IToolTipControlProvider ControlProvider
  298. {
  299. get;
  300. set;
  301. }
  302. public DateTime Date
  303. {
  304. get;
  305. set;
  306. }
  307. public bool Flag
  308. {
  309. get;
  310. set;
  311. }
  312. public Point Point
  313. {
  314. get;
  315. set;
  316. }
  317. public string Title
  318. {
  319. get;
  320. set;
  321. }
  322. public UIElement UIElement
  323. {
  324. get;
  325. set;
  326. }
  327. #endregion Public Properties
  328. #endregion Properties
  329. }
  330. }