Ejemplo n.º 1
0
        /// <summary>
        /// Displays textbox with layer name.
        /// </summary>
        private void ShowTextBox(int layerHandle)
        {
            var layer = Layers.ItemByHandle(layerHandle) as LegendLayer;

            if (layer == null)
            {
                return;
            }

            var el = layer.Elements.FirstOrDefault(item => item.Type == LayerElementType.Name &&
                                                   item.LayerHandle == layer.Handle);

            if (el == null)
            {
                return;
            }

            var txt = TextBox;

            txt.Visible = true;

            txt.Left   = el.Left;
            txt.Top    = el.Top;
            txt.Width  = el.Width;
            txt.Height = el.Height;

            if (txt.Height > el.Height)
            {
                int dy = Convert.ToInt32((txt.Height - el.Height) / 2.0);
                txt.Top -= dy;
            }

            txt.Text = layer.Name;
            txt.SelectAll();

            txt.LostFocus += txt_LostFocus;
            txt.KeyDown   += txt_KeyDown;

            Controls.Add(TextBox);
            TextBox.Focus();

            _activeElement = el;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Locates the layer that was clicked on in the legend.
        /// </summary>
        public LegendLayer FindClickedLayer(Point point, out LegendElement element)
        {
            element = new LegendElement(LayerElementType.None, new Rectangle());

            var groups = _legend.Groups as LegendGroups;

            if (groups == null)
            {
                return(null);
            }

            var groupCount = groups.Count;

            for (var i = 0; i < groupCount; i++)
            {
                var grp = GetGroup(i);

                if (!grp.Expanded)
                {
                    continue;
                }

                var layerCount = grp.Layers.Count;

                for (var j = 0; j < layerCount; j++)
                {
                    var lyr = grp.LayersList[j];

                    element = FindClickedLayerElement(point, lyr);

                    if (element != null)
                    {
                        element.GroupIndex  = i;
                        element.LayerHandle = lyr.Handle;
                        return(lyr);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
 public LegendLayer FindClickedLayer(Point point, out LegendElement element)
 {
     return(HitTest.FindClickedLayer(point, out element));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Runs appropriate handler for the element that was clicked. If no handler is found false is returned.
        /// </summary>
        private bool OnLayerElementClicked(LegendLayer lyr, LegendElement element)
        {
            switch (element.Type)
            {
            case LayerElementType.RasterColorBox:
            case LayerElementType.ColorBox:
                if (element.Index == -1)
                {
                    FireEvent(this, LayerStyleClicked, new LayerEventArgs(lyr.Handle));
                }
                else
                {
                    FireEvent(this, LayerCategoryClicked, new LayerCategoryEventArgs(lyr.Handle, MouseButtons.Left, element.Index));
                }
                break;

            case LayerElementType.Label:
                FireEvent(this, LayerLabelsClicked, new LayerEventArgs(lyr.Handle));
                break;

            case LayerElementType.Charts:
            case LayerElementType.ChartField:
            case LayerElementType.ChartFieldName:
                FireEvent(this, LayerDiagramsClicked, new LayerMouseEventArgs(lyr.Handle, MouseButtons.Left));

                // event for individual fields can be fired if necessary
                // FireEvent(this, LayerDiagramFieldClicked, new ChartFieldClickedEventArgs(lyr.Handle, MouseButtons.Left, element.Index));
                break;

            case LayerElementType.CategoryCheckbox:
                var sf = AxMap.get_Shapefile(lyr.Handle);
                if (sf != null)
                {
                    var ct = sf.Categories.Item[element.Index];
                    if (ct != null)
                    {
                        bool state = ct.DrawingOptions.Visible;
                        ct.DrawingOptions.Visible = !state;
                        AxMap.Redraw();
                    }
                }
                break;

            case LayerElementType.CheckBox:
            {
                var newState = !AxMap.get_LayerVisible(lyr.Handle);

                var args = new LayerCancelEventArgs(lyr.Handle, newState);
                FireEvent(this, LayerVisibleChanged, args);

                if (args.Cancel)
                {
                    return(true);
                }

                AxMap.set_LayerVisible(lyr.Handle, newState);

                var group = GetGroup(element.GroupIndex);
                group.UpdateGroupVisibility();

                FireEvent(this, LayerCheckboxClicked, new LayerEventArgs(lyr.Handle));
            }
            break;

            case LayerElementType.ExpansionBox:
            {
                Lock();
                lyr.Expanded = !lyr.Expanded;
                FireEvent(this, LayerPropertiesChanged, new LayerEventArgs(lyr.Handle));
                Unlock();
                return(true);
            }

            case LayerElementType.CategoriesCaption:
            case LayerElementType.ChartsCaption:
                Logger.Current.Info("Legend element clicked: " + element.Type + ". No handler is attached");
                return(true);

            case LayerElementType.Name:
            case LayerElementType.None:
            default:
                return(false);
            }

            Redraw();

            return(true);
        }