Exemple #1
0
        /// <summary>
        /// Layer was clicked outside any of its active elements
        /// </summary>
        private void OnLayerCaptionClicked(Point pnt, LegendLayer lyr, LegendGroup grp)
        {
            if (SelectedLayerHandle != lyr.Handle)
            {
                // a click on another layer; if there will be a second one in time
                // we shall display propeties, but editing must not start unless there is
                // one more click
                //Debug.WriteLine("First click on unselected layer.");
                _clickInfo.IsFirstClick = false;
                _clickInfo.StartTimer(lyr.Handle, true);
            }
            else
            {
                if (_clickInfo.IsFirstClick)
                {
                    // layer already selected, either editing or properties can be invoked
                    // depending on the presence of the second click in time
                    //Debug.WriteLine("A click on selected layer.");
                    _clickInfo.StartTimer(lyr.Handle, false);
                }
                else
                {
                    _clickInfo.IsDoubleClick = _clickInfo.Milliseconds < SystemInformation.DoubleClickTime;
                    //Debug.WriteLine("Second click on the selected layer. Is double click: " + _clickInfo.IsDoubleClick);
                    return;
                }
            }

            // Start dragging operation only if the clicked layer is selected.
            // Otherwise LayerSelected event will be fired which might results in a dialog box
            // from plugin code (TableEditor) and no Legend.MouseUp event (the dragging operation won't be finished).
            if (SelectedLayerHandle == lyr.Handle)
            {
                if (Groups.Count > 1 || grp.Layers.Count > 1)
                {
                    _dragInfo.StartLayerDrag(
                        pnt.Y,
                        Groups.PositionOf(grp.Handle),
                        grp.LayerPositionInGroup(lyr.Handle));
                }
            }

            SelectedLayerHandle = lyr.Handle;

            FireEvent(this, LayerMouseDown, new LayerMouseEventArgs(lyr.Handle, MouseButtons.Left));
        }
Exemple #2
0
        private LegendElement FindClickedLayerElement(Point point, LegendLayer layer)
        {
            const int left   = Constants.ListItemIndent;
            var       top    = layer.Top;
            var       width  = _legend.Width - left - Constants.ItemRightPad;
            var       height = layer.Height;
            var       bounds = new Rectangle(left, top, width, height);

            if (!bounds.Contains(point))
            {
                return(null);
            }

            var elements = layer.Elements.OrderBy(el => (int)el.Type);

            return(elements.FirstOrDefault(el => el.PointWithin(point)));
        }
Exemple #3
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);
        }