//-------------------------------------------------------------
//
// Copyright © Microsoft Corporation. All Rights Reserved.
//
//-------------------------------------------------------------
// @owner=alexgor, deliant
//=================================================================
// File: CommonElements.cs
//
// Namespace: DataVisualization.Charting
//
// Classes: CommonElements
//
// Purpose: CommonElements class provides references to common
// chart classes like DataManager, ChartTypeRegistry,
// ImageLoader and others. It is passed to different
// chart elements to simplify access to those common
// classes.
//
// Reviewed: GS - August 2, 2002
// AG - August 8, 2002
// AG - Microsoft 15, 2007
//
//===================================================================
#region Used namespaces
using System;
using System.ComponentModel.Design;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Globalization;
#if Microsoft_CONTROL
using System.Windows.Forms.DataVisualization.Charting.Data;
using System.Windows.Forms.DataVisualization.Charting.ChartTypes;
using System.Windows.Forms.DataVisualization.Charting.Utilities;
using System.Windows.Forms.DataVisualization.Charting.Borders3D;
using System.Windows.Forms.DataVisualization.Charting;
using System.Windows.Forms.DataVisualization.Charting.Formulas;
#else
using System.Web.UI.DataVisualization.Charting.ChartTypes;
using System.Web.UI.DataVisualization.Charting.Data;
using System.Web.UI.DataVisualization.Charting.Utilities;
using System.Web.UI.DataVisualization.Charting.Borders3D;
using System.Web.UI.DataVisualization.Charting.Formulas;
#endif
#endregion
#if Microsoft_CONTROL
namespace System.Windows.Forms.DataVisualization.Charting
#else
namespace System.Web.UI.DataVisualization.Charting
#endif
{
///
/// CommonElements class provides references to common chart classes like
/// DataManager, ChartTypeRegistry, ImageLoader and others. It is passed
/// to different chart elements to simplify access to those common classes.
///
internal class CommonElements
{
#region Fields
private Chart _chart;
private ChartImage _chartPicture;
// Reference to Chart Graphics Object
internal ChartGraphics graph = null;
///
/// Service Container
///
internal IServiceContainer container = null;
///
/// Indicates painting mode
///
internal bool processModePaint = true;
///
/// Indicates selection mode
///
internal bool processModeRegions = false;
// Private Fields
private int _width = 0;
private int _height = 0;
#endregion
#region Properties
///
/// Reference to the Data Manager
///
internal DataManager DataManager
{
get
{
return (DataManager)container.GetService(typeof(DataManager));
}
}
///
/// True if painting mode is active
///
public bool ProcessModePaint
{
get
{
return processModePaint;
}
}
///
/// True if Hot region or image maps mode is active
///
public bool ProcessModeRegions
{
get
{
return processModeRegions;
}
}
///
/// Reference to the hot regions object
///
public HotRegionsList HotRegionsList
{
get
{
return ChartPicture.hotRegionsList;
}
}
///
/// Reference to the Data Manipulator
///
public DataManipulator DataManipulator
{
get
{
return ChartPicture.DataManipulator;
}
}
///
/// Reference to the ImageLoader
///
internal ImageLoader ImageLoader
{
get
{
return (ImageLoader)container.GetService(typeof(ImageLoader));
}
}
///
/// Reference to the Chart
///
internal Chart Chart
{
get
{
if (_chart==null)
_chart = (Chart)container.GetService(typeof(Chart));
return _chart;
}
}
///
/// Reference to the ChartTypeRegistry
///
internal ChartTypeRegistry ChartTypeRegistry
{
get
{
return (ChartTypeRegistry)container.GetService(typeof(ChartTypeRegistry));
}
}
///
/// Reference to the BorderTypeRegistry
///
internal BorderTypeRegistry BorderTypeRegistry
{
get
{
return (BorderTypeRegistry)container.GetService(typeof(BorderTypeRegistry));
}
}
///
/// Reference to the FormulaRegistry
///
internal FormulaRegistry FormulaRegistry
{
get
{
return (FormulaRegistry)container.GetService(typeof(FormulaRegistry));
}
}
///
/// Reference to the ChartPicture
///
internal ChartImage ChartPicture
{
get
{
if (_chartPicture ==null)
_chartPicture = (ChartImage)container.GetService(typeof(ChartImage));
return _chartPicture;
}
}
///
/// Width of the chart picture
///
internal int Width
{
get
{
return _width;
}
set
{
_width = value;
}
}
///
/// Height of the chart picture
///
internal int Height
{
get
{
return _height;
}
set
{
_height = value;
}
}
#endregion
#region Methods
///
/// Constructor
///
/// Service container.
internal CommonElements(IServiceContainer container)
{
this.container = container;
}
#endregion
#region String convertion helper methods
///
/// Converts string to double.
///
/// String to convert.
/// Double result.
internal static double ParseDouble(string stringToParse)
{
return ParseDouble(stringToParse, false);
}
///
/// Converts string to double.
///
/// String to convert.
/// if set to true the exception thrown.
/// Double result.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "System.Double.TryParse(System.String,System.Globalization.NumberStyles,System.IFormatProvider,System.Double@)")]
internal static double ParseDouble(string stringToParse, bool throwException)
{
Double result = 0.0;
if (throwException)
{
result = double.Parse(stringToParse, NumberStyles.Any, CultureInfo.InvariantCulture);
}
else
{
bool parseSucceed = double.TryParse(stringToParse, NumberStyles.Any, CultureInfo.InvariantCulture, out result);
if (!parseSucceed)
{
double.TryParse(stringToParse, NumberStyles.Any, CultureInfo.CurrentCulture, out result);
}
}
return result;
}
///
/// Converts string to double.
///
/// String to convert.
/// Double result.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "System.Single.TryParse(System.String,System.Globalization.NumberStyles,System.IFormatProvider,System.Single@)")]
internal static float ParseFloat(string stringToParse)
{
float result = 0f;
bool parseSucceed = float.TryParse(stringToParse, NumberStyles.Any, CultureInfo.InvariantCulture, out result);
if (!parseSucceed)
{
float.TryParse(stringToParse, NumberStyles.Any, CultureInfo.CurrentCulture, out result);
}
return result;
}
#endregion
}
}