/// <summary>
        /// Cancels the changes made by user
        /// </summary>
        private void CancelChanges()
        {
            var map = _legend.Map;

            if (map != null)
            {
                string state = map.SerializeLayer(_layerHandle);

                if (state != _initState)
                {
                    // label and chart data must not be serialized
                    tkSavingMode mode1 = _shapefile.Labels.SavingMode;
                    tkSavingMode mode2 = _shapefile.Charts.SavingMode;

                    _shapefile.Labels.SavingMode = tkSavingMode.modeNone;
                    _shapefile.Charts.SavingMode = tkSavingMode.modeNone;

                    bool res = map.DeserializeLayer(_layerHandle, _initState);

                    _shapefile.Labels.SavingMode = mode1;
                    _shapefile.Charts.SavingMode = mode2;

                    _legend.Map.Redraw();
                    _legend.Refresh();
                }
            }

            LockLegendAndMap(false);
        }
 /// <summary>
 /// Reverts the changes if cancel was hit
 /// </summary>
 private void frmLabelStyle_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (this.DialogResult == DialogResult.Cancel)
     {
         if (m_categoryEdited)
         {
             m_category.Deserialize(m_initState);
         }
         else
         {
             tkSavingMode mode = m_shapefile.Labels.SavingMode;
             m_shapefile.Labels.SavingMode = tkSavingMode.modeNone;
             m_shapefile.Labels.Deserialize(m_initState);
             m_shapefile.Labels.SavingMode = mode;
         }
     }
 }
        private string SaveState()
        {
            string state = "";
            var    map   = _legend.Map;

            if (map != null)
            {
                tkSavingMode mode1 = _shapefile.Labels.SavingMode;
                tkSavingMode mode2 = _shapefile.Charts.SavingMode;

                _shapefile.Labels.SavingMode = tkSavingMode.modeNone;
                _shapefile.Charts.SavingMode = tkSavingMode.modeNone;

                state = map.SerializeLayer(_layerHandle);

                _shapefile.Labels.SavingMode = mode1;
                _shapefile.Charts.SavingMode = mode2;
            }
            return(state);
        }
        /// <summary>
        /// Saves the state in the m_InitState variable
        /// </summary>
        private string SaveState()
        {
            string state = "";
            var    map   = _legend.Map;

            if (map != null)
            {
                // serializing for undo (label and chart data must not be serialized)
                tkSavingMode mode1 = _shapefile.Labels.SavingMode;
                tkSavingMode mode2 = _shapefile.Charts.SavingMode;

                _shapefile.Labels.SavingMode = tkSavingMode.modeNone;
                _shapefile.Charts.SavingMode = tkSavingMode.modeNone;

                state = map.SerializeLayer(_layerHandle);

                _shapefile.Labels.SavingMode = mode1;
                _shapefile.Charts.SavingMode = mode2;
            }
            return(state);
        }
        /// <summary>
        /// Initializes controls of the form
        /// </summary>
        private void Initialize(LabelCategory lb)
        {
            m_category = lb;

            m_NoEvents = true;
            cboFontName.Items.Clear();
            foreach (FontFamily family in FontFamily.Families)
            {
                cboFontName.Items.Add(family.Name);
            }

            cboDecimalPlaces.Items.Add("Auto");
            for (int i = 1; i <= 6; i++)
            {
                cboDecimalPlaces.Items.Add(i.ToString());
            }
            cboDecimalPlaces.SelectedIndex = 0;

            icbLineType.ComboStyle  = ImageComboStyle.LineStyle;
            icbLineWidth.ComboStyle = ImageComboStyle.LineWidth;

            icbFrameType.Color1        = Color.Transparent;
            icbFrameType.ComboStyle    = ImageComboStyle.FrameType;
            icbFrameType.SelectedIndex = 0;

            if (!m_categoryEdited)
            {
                for (int i = 0; i < m_shapefile.NumFields; i++)
                {
                    string name = m_shapefile.Field[i].Name;
                    if (name.ToLower() != "mwshapeid")
                    {
                        listBox1.Items.Add(name);
                    }
                }
            }

            string[] scales = { "1",      "10",     "100",     "1000", "5000", "10000", "25000", "50000", "100000",
                                "250000", "500000", "1000000", "10000000" };
            cboMinScale.Items.Clear();
            cboMaxScale.Items.Clear();
            cboBasicScale.Items.Clear();
            foreach (string t in scales)
            {
                cboMinScale.Items.Add(t);
                cboMaxScale.Items.Add(t);
                cboBasicScale.Items.Add(t);
            }

            // displaying options in the GUI
            LabelStyle2Gui(m_category);

            btnTest_Click(null, null);

            txtLabelExpression.Text = m_shapefile.Labels.VisibilityExpression;

            // serialization
            if (m_categoryEdited)
            {
                m_initState = m_category.Serialize();
            }
            else
            {
                tkSavingMode mode = m_shapefile.Labels.SavingMode;
                m_shapefile.Labels.SavingMode = tkSavingMode.modeNone;
                m_initState = m_shapefile.Labels.Serialize();
                m_shapefile.Labels.SavingMode = mode;
            }

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

            var labels = m_shapefile.Labels;

            cboLabelsVerticalPosition.SelectedIndex = (int)labels.VerticalPosition;
            chkLabelsRemoveDuplicates.Checked       = labels.RemoveDuplicates;
            chkAviodCollisions.Checked = labels.AvoidCollisions;
            chkScaleLabels.Checked     = labels.ScaleLabels;
            cboBasicScale.Text         = labels.BasicScale.ToString();

            udLabelOffsetX.SetValue(labels.OffsetX);
            udLabelOffsetY.SetValue(labels.OffsetY);
            udLabelsBuffer.SetValue(labels.CollisionBuffer);

            // alignment
            optAlignBottomCenter.Checked = (labels.Alignment == tkLabelAlignment.laBottomCenter);
            optAlignBottomLeft.Checked   = (labels.Alignment == tkLabelAlignment.laBottomLeft);
            optAlignBottomRight.Checked  = (labels.Alignment == tkLabelAlignment.laBottomRight);
            optAlignCenter.Checked       = (labels.Alignment == tkLabelAlignment.laCenter);
            optAlignCenterLeft.Checked   = (labels.Alignment == tkLabelAlignment.laCenterLeft);
            optAlignCenterRight.Checked  = (labels.Alignment == tkLabelAlignment.laCenterRight);
            optAlignTopCenter.Checked    = (labels.Alignment == tkLabelAlignment.laTopCenter);
            optAlignTopLeft.Checked      = (labels.Alignment == tkLabelAlignment.laTopLeft);
            optAlignTopRight.Checked     = (labels.Alignment == tkLabelAlignment.laTopRight);

            ShpfileType shpType = Globals.ShapefileType2D(m_shapefile.ShapefileType);

            optAlignCenter.Enabled = (shpType != ShpfileType.SHP_POINT && shpType != ShpfileType.SHP_MULTIPOINT);

            btnApply.Enabled = (m_shapefile.Labels.Expression != "" && m_shapefile.Labels.Count == 0);
            string[] list = new string[] {
                "Default",
                "SingleBitPerPixelGridFit",
                "SingleBitPerPixel",
                "AntiAliasGridFit",
                "HintAntiAlias",
                "ClearType"
            };
            cboTextRenderingHint.DataSource = list;
            SetSelectedIndex(cboTextRenderingHint, (int)m_shapefile.Labels.TextRenderingHint);
            cboTextRenderingHint.SelectedIndexChanged += Gui2LabelStyle;

            m_NoEvents = false;

            // initial drawing
            this.DrawPreview(null, null);
        }