Example #1
0
        protected internal int CalcHeight(bool UseExpandedHeight)
        {
            // to affect drawing of the expansion box externally
            if (m_Expanded && ExpansionBoxCustomHeightFunction != null)
            {
                int  ht      = Constants.ITEM_HEIGHT;
                bool Handled = false;
                ExpansionBoxCustomHeightFunction(m_Handle, m_Legend.Width, ref ht, ref Handled);
                if (Handled)
                {
                    return(ht + Constants.ITEM_HEIGHT + Constants.EXPAND_BOX_TOP_PAD * 2);
                }
                else
                {
                    return(Constants.ITEM_HEIGHT);
                }
            }

            int ret = 0;

            if (this.Type == eLayerType.Grid || this.Type == eLayerType.Image)
            {
                if (UseExpandedHeight == false && (m_Expanded == false || ColorLegend.Count == 0)) //|| (this.Type == eLayerType.Image))
                {
                    ret = Constants.ITEM_HEIGHT;
                }
                else
                {
                    ret = Constants.ITEM_HEIGHT + (ColorLegend.Count * Constants.CS_ITEM_HEIGHT) + 2;
                }


                if (UseExpandedHeight || m_Expanded)
                {
                    ret += (ColorSchemeFieldCaption.Trim() != "" ? Constants.CS_ITEM_HEIGHT : 0) + (StippleSchemeFieldCaption.Trim() != "" ? Constants.CS_ITEM_HEIGHT : 0);
                }
            }
            else
            {
                var sf = m_Legend.m_Map.get_Shapefile(this.Handle);

                if ((UseExpandedHeight || m_Expanded) && sf != null)
                {
                    ret = Constants.ITEM_HEIGHT + 2;                            // 图层名


                    int val1, val2;
                    val1 = (GetCategoryHeight(sf.DefaultDrawingOptions) + 2);  // 默认图例

                    if (sf.Labels.Count == 0 || sf.Labels.Visible == false || true)
                    {
                        ret += val1;
                    }
                    else
                    {
                        LabelStyle            style = new LabelStyle(sf.Labels.Options);
                        System.Drawing.Bitmap img   = new System.Drawing.Bitmap(500, 200);
                        Graphics g    = Graphics.FromImage(img);
                        Size     size = style.MeasureString(g, "String", 30);
                        val2 = size.Height + 2;
                        ret += val1 > val2 ? val1 : val2;
                    }

                    if (sf.Categories.Count > 0)
                    {
                        ret += Constants.CS_ITEM_HEIGHT + 2;   // 标题

                        MapWinGIS.ShapefileCategories categories = sf.Categories;
                        if (this.Type == eLayerType.LineShapefile || this.Type == eLayerType.PolygonShapefile)
                        {
                            ret += sf.Categories.Count * (Constants.CS_ITEM_HEIGHT + 2);
                        }
                        else
                        {
                            for (int i = 0; i < sf.Categories.Count; i++)
                            {
                                ret += GetCategoryHeight(categories.get_Item(i).DrawingOptions);
                            }
                        }
                        ret += 2;
                    }

                    if (sf.Charts.Count > 0 && sf.Charts.NumFields > 0 && sf.Charts.Visible)
                    {
                        ret += (Constants.CS_ITEM_HEIGHT + 2);   // 标题
                        ret += sf.Charts.IconHeight;
                        ret += 2;

                        ret += (sf.Charts.NumFields * (Constants.CS_ITEM_HEIGHT + 2));
                    }
                }
                else
                {
                    ret = Constants.ITEM_HEIGHT;
                }

                // TODO: 标题宽度
                //if (UseExpandedHeight || m_Expanded)
                //    ret += (ColorSchemeFieldCaption.Trim() != "" ? Constants.CS_ITEM_HEIGHT : 0) + (StippleSchemeFieldCaption.Trim() != "" ? Constants.CS_ITEM_HEIGHT : 0);
            }

            m_height = ret;

            return(ret);
        }