/*
Copyright (C) 2008 Webyog Softworks Private Limited
This file is a part of Visifire Charts.
Visifire is a free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General Public License
along with Visifire Charts. If not, see .
If GPL is not suitable for your products or company, Webyog provides Visifire
under a flexible commercial license designed to meet your specific usage and
distribution requirements. If you have already obtained a commercial license
from Webyog, you can use this file under those license terms.
*/
#if WPF
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.ComponentModel;
#else
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Collections.Generic;
#endif
using System.Windows.Input;
namespace Visifire.Charts
{
///
/// Visifire.Charts.ToolTip class
///
#if SL
[System.Windows.Browser.ScriptableType]
#endif
public class ToolTip : Visifire.Commons.VisifireElement
{
#region Public Methods
///
/// Initializes a new instance of the Visifire.Charts.ToolTip class
///
public ToolTip()
{
Text = "";
// Apply default style from generic
#if WPF
if (!_defaultStyleKeyApplied)
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ToolTip), new FrameworkPropertyMetadata(typeof(ToolTip)));
_defaultStyleKeyApplied = true;
}
#else
DefaultStyleKey = typeof(ToolTip);
#endif
}
///
/// When overridden in a derived class, is invoked whenever application code
/// or internal processes (such as a rebuilding layout pass) call System.Windows.Controls.Control.ApplyTemplate().
///
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_borderElement = GetTemplateChild("ToolTipBorder") as Border;
_toolTipTextBlock = GetTemplateChild("ToolTipTextBlock") as TextBlock;
_toolTipTextBlock.LineHeight = (Int32)(_toolTipTextBlock.FontSize * 1.4);
this.Visibility = Visibility.Collapsed;
}
#endregion
#region Public Properties
///
/// Identifies the Visifire.Charts.ToolTip.Enabled dependency property.
///
///
/// The identifier for the Visifire.Charts.ToolTip.Enabled dependency property.
///
public static readonly DependencyProperty EnabledProperty = DependencyProperty.Register
("Enabled",
typeof(Nullable),
typeof(ToolTip),
new PropertyMetadata(OnEnabledPropertyChanged));
///
/// Identifies the Visifire.Charts.ToolTip.Text dependency property.
///
///
/// The identifier for the Visifire.Charts.ToolTip.Text dependency property.
///
public static readonly DependencyProperty TextProperty = DependencyProperty.Register
("Text",
typeof(String),
typeof(ToolTip),
new PropertyMetadata(OnTextPropertyChanged));
///
/// Identifies the Visifire.Charts.ToolTip.CornerRadius dependency property.
///
///
/// The identifier for the Visifire.Charts.ToolTip.CornerRadius dependency property.
///
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register
("CornerRadius",
typeof(CornerRadius),
typeof(ToolTip),
null);
///
/// Identifies the Visifire.Charts.ToolTip.FontColor dependency property.
///
///
/// The identifier for the Visifire.Charts.ToolTip.FontColor dependency property.
///
public static readonly DependencyProperty FontColorProperty = DependencyProperty.Register
("FontColor",
typeof(Brush),
typeof(ToolTip),
null);
///
/// Visifire chart control reference
///
#if WPF
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
#endif
public Visifire.Commons.VisifireControl Chart
{
get;
set;
}
///
/// Enables or disables the ToolTip
///
[System.ComponentModel.TypeConverter(typeof(NullableBoolConverter))]
public Nullable Enabled
{
get
{
if ((Nullable)GetValue(EnabledProperty) == null)
{
if (Chart != null)
return Chart.ToolTipEnabled;
else
return true;
}
else
{
return (Nullable)GetValue(EnabledProperty);
}
}
set
{
SetValue(EnabledProperty, value);
}
}
///
/// Get or set the Text property of ToolTip
///
public String Text
{
get
{
return (GetValue(TextProperty) == null) ? "" : (String)GetValue(TextProperty);
}
set
{
String val = Visifire.Commons.ObservableObject.GetFormattedMultilineText(value);
SetValue(TextProperty, val);
}
}
///
/// Get or set the CornerRadius property of ToolTip
///
public CornerRadius CornerRadius
{
get
{
return (CornerRadius)GetValue(CornerRadiusProperty);
}
set
{
SetValue(CornerRadiusProperty, value);
}
}
///
/// Get or set the FontColor of ToolTip Text
///
public Brush FontColor
{
get
{
return (Brush)GetValue(FontColorProperty);
}
set
{
SetValue(FontColorProperty, value);
}
}
#endregion
#region Public Events And Delegates
#endregion
#region Protected Methods
#endregion
#region Internal Properties
#endregion
#region Private Properties
#endregion
#region Private Delegates
#endregion
#region Private Methods
///
/// EnabledProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ToolTip t = d as ToolTip;
if (t._borderElement != null)
{
if ((Boolean)e.NewValue)
t._borderElement.Visibility = t.Visibility;
else
t._borderElement.Visibility = Visibility.Collapsed;
}
}
///
/// TextProperty changed call back function
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ToolTip tootlTip = d as ToolTip;
if (tootlTip._toolTipTextBlock != null)
tootlTip._toolTipTextBlock.Text = (String)e.NewValue;
if (tootlTip.Chart != null)
{
tootlTip.MaxWidth = tootlTip.Chart.ActualWidth;
if (tootlTip._toolTipTextBlock != null)
tootlTip._toolTipTextBlock.MaxWidth = tootlTip.Chart.ActualWidth - 4;
}
}
#endregion
#region Internal Methods
///
/// Show ToolTip
///
internal void Show()
{
if ((Boolean)Enabled)
{
if (Text == String.Empty)
Hide();
else
this.Visibility = Visibility.Visible;
}
else
Hide();
}
///
/// Hide ToolTip
///
internal void Hide()
{
this.Visibility = Visibility.Collapsed;
}
#endregion
#region Internal Events And Delegates
#endregion
#region Data
///
/// Border element of ToolTip
///
internal Border _borderElement;
///
/// TextBlock element of ToolTip
///
private TextBlock _toolTipTextBlock;
#if WPF
///
/// Whether the default style is applied
///
private static Boolean _defaultStyleKeyApplied;
#endif
#endregion
}
}