using Microsoft.VisualBasic.CompilerServices; using MuchInfo.Chart.Data.Interfaces; using System; using System.Runtime.CompilerServices; using System.Threading; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Media; namespace MuchInfo.Chart.Infrastructure.Helpers { public class ChartToolTip { //#region Fields //private static Border border; //private static object monitorObject = RuntimeHelpers.GetObjectValue(new object()); //private static Popup popupDialog; //private static TextBlock textBlock; //private static ToolTipContent ToolTipContent; //private static Thread wbiToolTip_626; //#endregion Fields //#region Properties //#region Private Static Properties //private static Border Border //{ // get // { // return border; // } // set // { // var sizeChangedEventHandler = new SizeChangedEventHandler(OnBorderSizeChanged); // if (border != null) // { // border.SizeChanged -= sizeChangedEventHandler; // } // border = value; // if (border != null) // { // border.SizeChanged += (sizeChangedEventHandler); // } // } //} //#endregion Private Static Properties //#endregion Properties //#region Methods //#region Public Static Methods ////public static void ShowTip(UIElement aCtrl, MouseEventArgs e, string txt, Panel rootPanel) ////{ //// object obj = monitorObject; //// ObjectFlowControl.CheckForSyncLockOnValueType(obj); //// Monitor.Enter(obj); //// try //// { //// bool flag = ToolTipContent == null || !ToolTipContent.UIElement.Equals(aCtrl); //// if (flag) //// { //// Clean(rootPanel); //// } //// flag = (ToolTipContent != null); //// if (flag) //// { //// ToolTipContent.Flag = true; //// } //// ToolTipContent = new ToolTipContent //// { //// Point = e.GetPosition(rootPanel), //// Title = txt, //// UIElement = aCtrl //// }; //// flag = (wbiToolTip_626 == null); //// if (flag) //// { //// wbiToolTip_626 = new Thread(new ThreadStart(wbiToolTip_1677)) {IsBackground = (true)}; //// wbiToolTip_626.Start(); //// } //// } //// finally //// { //// Monitor.Exit(obj); //// } ////} //public static void ShowTip(UIElement control, MouseEventArgs args, IToolTipControlProvider controlProvider, Panel rootPanel) //{ // object obj = ChartToolTip.monitorObject; // //ObjectFlowControl.CheckForSyncLockOnValueType(obj); // Monitor.Enter(obj); // try // { // if (ToolTipContent == null || ToolTipContent.UIElement != control) // { // Clean(rootPanel); // } // if (ToolTipContent != null) // { // ToolTipContent.Flag = true; // } // ToolTipContent = new ToolTipContent // { // Point = args.GetPosition(rootPanel), // ControlProvider = controlProvider, // UIElement = control // }; // if (wbiToolTip_626 == null) // { // wbiToolTip_626 = new Thread(new ThreadStart(CreateToolTipThread)); // wbiToolTip_626.IsBackground = (true); // wbiToolTip_626.Start(); // } // } // finally // { // Monitor.Exit(obj); // } //} //public static void HideTip(UIElement aCtrl, Panel rootPanel) //{ // try // { // object obj = monitorObject; // ObjectFlowControl.CheckForSyncLockOnValueType(obj); // Monitor.Enter(obj); // try // { // bool flag = ToolTipContent != null && ToolTipContent.UIElement == aCtrl; // if (flag) // { // ToolTipContent.Flag = true; // ToolTipContent = null; // Clean(rootPanel); // } // } // finally // { // Monitor.Exit(obj); // } // } // catch (Exception expr_7D) // { // ProjectData.SetProjectError(expr_7D); // ProjectData.ClearProjectError(); // } //} //private static void Clean(Panel rootPanel) //{ // if (popupDialog != null) // { // rootPanel.Children.Remove(popupDialog); // popupDialog = null; // border = null; // textBlock = null; // } //} ////private static void wbiToolTip_1677() ////{ //// while (true) //// { //// try //// { //// Thread.Sleep(100); //// PopupManager.PopupRoot.Dispatcher.BeginInvoke(new Action(CreateToolTip)); //// } //// catch (Exception expr_4E) //// { //// ProjectData.SetProjectError(expr_4E); //// ProjectData.ClearProjectError(); //// } //// } ////} //#endregion Public Static Methods //#region Private Static Methods //private static void CreatePopUp() //{ // //object obj = monitorObject; // //ObjectFlowControl.CheckForSyncLockOnValueType(obj); // ////Monitor.Enter(obj); // //try // //{ // popupDialog = new Popup(); // popupDialog.Visibility = Visibility.Hidden; // popupDialog.Name = "ToolTip_Pop"; // PopupManager.PopupRoot.Children.Add(popupDialog); // var border = new Border(); // border.BorderBrush = (new SolidColorBrush(Colors.Black)); // border.BorderThickness = new Thickness(1.0); // border.Padding = new Thickness(3.0); // border.Background = new SolidColorBrush(Colors.LightGray); // popupDialog.Child = border; // textBlock = new TextBlock(); // border.Child = textBlock; // Border = border; // //} // //finally // //{ // // Monitor.Exit(obj); // //} //} //private static void CreateToolTip() //{ // //object obj = monitorObject; // ////ObjectFlowControl.CheckForSyncLockOnValueType(obj); // //try // //{ // // Monitor.Enter(obj); // if (ToolTipContent != null && DateTime.Compare(ToolTipContent.Date, DateTime.Now) < 0 && popupDialog == null) // { // if (popupDialog == null) // { // CreatePopUp(); // } // if (ToolTipContent.ControlProvider != null) // { // Border.BorderBrush = (null); // Thickness thickness = new Thickness(); // Border.BorderThickness = (thickness); // Border.Padding = (thickness); // Border.Background = (null); // Border.Child = ((UIElement)ToolTipContent.ControlProvider.GetControl()); // } // else // { // Border.BorderBrush = (new SolidColorBrush(Colors.Black)); // Border.BorderThickness = new Thickness(1.0); // Border.Padding = new Thickness(3.0); // Border.Background = (new SolidColorBrush(Colors.LightGray)); // Border.Child = textBlock; // textBlock.Text = ToolTipContent.Title; // } // popupDialog.HorizontalOffset = ToolTipContent.Point.X + 12.0; // popupDialog.VerticalOffset = ToolTipContent.Point.Y + 12.0; // popupDialog.Visibility = Visibility.Visible; // popupDialog.IsOpen = true; // textBlock.UpdateLayout(); // GeometryHelper.EnsureControlInApplication(popupDialog); // } // else // { // if (popupDialog != null && ToolTipContent != null && popupDialog.IsOpen && DateTime.Compare(ToolTipContent.Date.AddSeconds(5.0), DateTime.Now) < 0) // { // ToolTipContent = null; // Clean(); // } // else // { // if (popupDialog != null && popupDialog.IsOpen && ToolTipContent == null) // { // Clean(); // } // } // } // //} // //finally // //{ // // Monitor.Exit(obj); // //} //} ////private static void CreateToolTipThread() ////{ //// while (true) //// { //// try //// { //// Thread.Sleep(100); //// PopupManager.PopupRoot.Dispatcher.BeginInvoke(new Action(CreateToolTip)); //// } //// catch //// { //// } //// } ////} //private static void OnBorderSizeChanged(object sender, SizeChangedEventArgs e) //{ // try // { // GeometryHelper.EnsureControlInApplication(popupDialog); // } // catch (Exception ex) // { // throw ex; // } //} //#endregion Private Static Methods //#endregion Methods } internal class ToolTipContent { #region Constructors public ToolTipContent() { this.Date = DateTime.Now.AddSeconds(0.6); this.Flag = false; } #endregion Constructors #region Properties #region Public Properties public IToolTipControlProvider ControlProvider { get; set; } public DateTime Date { get; set; } public bool Flag { get; set; } public Point Point { get; set; } public string Title { get; set; } public UIElement UIElement { get; set; } #endregion Public Properties #endregion Properties } }