/// <summary>
        ///  Draws preview on the charts tab
        /// </summary>
        private void DrawChartsPreview()
        {
            Rectangle rect = pctCharts.ClientRectangle;
            Bitmap    bmp  = new Bitmap(rect.Width, rect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            if (_shapefile.Charts.Count > 0 && _shapefile.Charts.NumFields > 0)
            {
                Graphics g   = Graphics.FromImage(bmp);
                IntPtr   ptr = g.GetHdc();

                int width  = rect.Width;
                int height = rect.Height;

                MapWinGIS.Charts charts = _shapefile.Charts;

                if (charts.ChartType == MapWinGIS.tkChartType.chtPieChart)
                {
                    charts.DrawChart(ptr.ToInt32(), (width - charts.IconWidth) / 2, (height - charts.IconHeight) / 2, false, Colors.ColorToUInteger(Color.White));
                }
                else
                {
                    charts.DrawChart(ptr.ToInt32(), (width - charts.IconWidth) / 2, (height - charts.IconHeight) / 2, false, Colors.ColorToUInteger(Color.White));
                }

                g.ReleaseHdc(ptr);
            }
            pctCharts.Image = bmp;
        }
 /// <summary>
 /// Sets the properties of the labels based upon user input
 /// </summary>
 private void UpdateCharts()
 {
     MapWinGIS.Charts charts = _shapefile.Charts;
     charts.Visible   = chkChartsVisible.Checked;
     charts.ChartType = optChartBars.Checked ? MapWinGIS.tkChartType.chtBarChart : MapWinGIS.tkChartType.chtPieChart;
     this.UpdateFieldColors();
     DrawChartsPreview();
 }
        /// <summary>
        /// The code for initialization of the charts tab
        /// </summary>
        private void InitChartsTab()
        {
            icbChartColorScheme.ComboStyle = ImageComboStyle.ColorSchemeGraduated;
            //icbChartColorScheme.ColorSchemes = m_plugin.ChartColors;
            if (icbChartColorScheme.Items.Count > 0)
            {
                icbChartColorScheme.SelectedIndex = 0;
            }

            MapWinGIS.Charts charts = _shapefile.Charts;
            chkChartsVisible.Checked = charts.Visible;
            //cboChartVerticalPosition.SelectedIndex = (int)charts.VerticalPosition;

            optChartBars.Checked = (charts.ChartType == tkChartType.chtBarChart);
            optChartsPie.Checked = (charts.ChartType == tkChartType.chtPieChart);
        }
        /// <summary>
        /// Initializes a new instance of the ChartStyleForm class
        /// </summary>
        public ChartStyleForm(LegendControl.Legend legend, MapWinGIS.Shapefile sf, bool legendCall, int handle)
        {
            InitializeComponent();
            _shapefile = sf;
            _charts    = sf.Charts;
            m_legend   = legend;
            _handle    = handle;

            MapWinGIS.tkSavingMode mode = _charts.SavingMode;
            _charts.SavingMode = MapWinGIS.tkSavingMode.modeNone;
            _initState         = _charts.Serialize();
            _charts.SavingMode = mode;

            _noEvents = true;

            panelPieChart.Top  = panelBarChart.Top;
            panelPieChart.Left = panelBarChart.Left;

            foreach (FontFamily family in FontFamily.Families)
            {
                cboFontName.Items.Add(family.Name);
            }

            cboValuesStyle.Items.Clear();
            cboValuesStyle.Items.Add("Horizontal");
            cboValuesStyle.Items.Add("Vertical");

            cboChartVerticalPosition.Items.Clear();
            cboChartVerticalPosition.Items.Add("Above current layer");
            cboChartVerticalPosition.Items.Add("Above all layers");

            optBarCharts.Checked = (_charts.ChartType == MapWinGIS.tkChartType.chtBarChart);
            optPieCharts.Checked = (_charts.ChartType == MapWinGIS.tkChartType.chtPieChart);

            // initializing for list of color schemes
            icbColors.ColorSchemes = Globals.ChartColors;
            icbColors.ComboStyle   = ImageComboStyle.ColorSchemeGraduated;
            if (icbColors.Items.Count > 0)
            {
                icbColors.SelectedIndex = 0;
            }

            string[] scales = { "1",      "10",     "100",     "1000", "5000", "10000", "25000", "50000", "100000",
                                "250000", "500000", "1000000", "10000000" };
            cboMinScale.Items.Clear();
            cboMaxScale.Items.Clear();
            for (int i = 0; i < scales.Length; i++)
            {
                cboMinScale.Items.Add(scales[i]);
                cboMaxScale.Items.Add(scales[i]);
            }

            txtChartExpression.Text = sf.Charts.VisibilityExpression;

            SetChartsType();

            InitFields();

            _noEvents = false;

            Settings2GUI();

            Draw();

            RefreshControlsState();

            tabControl1.SelectedIndex = _selectedTab;
        }
        /// <summary>
        /// Fills the fields tab
        /// </summary>
        private void InitFields()
        {
            // building list of fields
            listLeft.Items.Clear();
            listRight.Items.Clear();
            for (int i = 0; i < _shapefile.NumFields; i++)
            {
                if (_shapefile.get_Field(i).Type != FieldType.STRING_FIELD)
                {
                    listLeft.Items.Add(_shapefile.get_Field(i).Name);
                }
            }

            // in case some fields have been chosen we must show them
            if (_shapefile.Charts.NumFields > 0)
            {
                for (int i = 0; i < _shapefile.Charts.NumFields; i++)
                {
                    string name = _shapefile.Charts.get_Field(i).Name.ToLower();
                    for (int j = 0; j < listLeft.Items.Count; j++)
                    {
                        if (listLeft.Items[j].ToString().ToLower() == name)
                        {
                            listRight.Items.Add(listLeft.Items[j]);
                            listLeft.Items.Remove(listLeft.Items[j]);
                            break;
                        }
                    }
                }
            }

            if (listLeft.Items.Count > 0)
            {
                listLeft.SelectedIndex = 0;
            }

            if (listRight.Items.Count > 0)
            {
                listRight.SelectedIndex = 0;
            }

            // Filling size and normalization fields
            cboChartSizeField.Items.Clear();
            cboChartNormalizationField.Items.Clear();

            cboChartSizeField.Items.Add("<None>");          // default
            cboChartNormalizationField.Items.Add("<None>");

            for (int i = 0; i < _shapefile.NumFields; i++)
            {
                MapWinGIS.Field fld = _shapefile.get_Field(i);
                if (fld.Type != FieldType.STRING_FIELD)
                {
                    cboChartSizeField.Items.Add(fld.Name);
                    cboChartNormalizationField.Items.Add(fld.Name);
                }
            }

            if (cboChartSizeField.Items.Count >= 0)
            {
                cboChartSizeField.SelectedIndex = 0;
            }

            if (cboChartNormalizationField.Items.Count >= 0)
            {
                cboChartNormalizationField.SelectedIndex = 0;
            }

            // size field
            MapWinGIS.Charts charts = _shapefile.Charts;
            if (charts.SizeField >= 0 && charts.SizeField < cboChartSizeField.Items.Count - 1)  // first item is <none>
            {
                Field fld = _shapefile.get_Field(charts.SizeField);
                if (fld != null)
                {
                    for (int i = 2; i < cboChartSizeField.Items.Count; i++)     // 2 = <none> and <sum of fields>
                    {
                        if (fld.Name == cboChartSizeField.Items[i].ToString())
                        {
                            cboChartSizeField.SelectedIndex = i;
                            break;
                        }
                    }
                }
            }
            else
            {
                cboChartSizeField.SelectedIndex = 0;
            }

            // normalization field
            if (charts.NormalizationField >= 0 && charts.NormalizationField < cboChartNormalizationField.Items.Count - 1)  // first item is <none>
            {
                Field fld = _shapefile.get_Field(charts.NormalizationField);
                if (fld != null)
                {
                    for (int i = 2; i < cboChartNormalizationField.Items.Count; i++)     // 2 = <none> and <sum of fields>
                    {
                        if (fld.Name == cboChartNormalizationField.Items[i].ToString())
                        {
                            cboChartNormalizationField.SelectedIndex = i;
                            break;
                        }
                    }
                }
            }
            else
            {
                cboChartNormalizationField.SelectedIndex = 0;
            }
        }