Exemplo n.º 1
0
        public bool DeleteActiveAnnotate()
        {
            if (SelectExists())
            {
                return(false);
            }

            bool vResult = false;

            if (FActiveAnnotate.BeginNo >= 0)
            {
                vResult = DeleteAnnotate(FActiveAnnotate.BeginNo, FActiveAnnotate.EndNo);
            }
            else
            if (Items[SelectInfo.StartItemNo].StyleNo < HCStyle.Null &&
                SelectInfo.StartItemOffset == HC.OffsetInner)
            {
                Undo_New();

                HCCustomRectItem vRectItem = Items[SelectInfo.StartItemNo] as HCCustomRectItem;
                if (vRectItem.MangerUndo)
                {
                    UndoAction_ItemSelf(SelectInfo.StartItemNo, HC.OffsetInner);
                }
                else
                {
                    UndoAction_ItemMirror(SelectInfo.StartItemNo, HC.OffsetInner);
                }

                vResult = (Items[SelectInfo.StartItemNo] as HCCustomRectItem).DeleteActiveAnnotate();
                if (vRectItem.IsFormatDirty)
                {
                    int vFirstDrawItemNo = -1, vLastItemNo = -1;
                    GetFormatRange(ref vFirstDrawItemNo, ref vLastItemNo);
                    FormatPrepare(vFirstDrawItemNo, vLastItemNo);
                    ReFormatData(vFirstDrawItemNo, vLastItemNo);
                }
                else
                {
                    this.FormatInit();
                }
            }

            return(vResult);
        }
Exemplo n.º 2
0
        private void DoFormatRectItemToDrawItem(HCCustomRectItem vRectItem, int aItemNo, int aFmtLeft, int aContentWidth, int aFmtRight, int aOffset,
                                                bool vParaFirst, ref POINT aPos, ref RECT vRect, ref bool vLineFirst, ref int aLastDrawItemNo, ref int vRemainderWidth)
        {
            vRectItem.FormatToDrawItem(this, aItemNo);
            int vWidth = aFmtRight - aPos.X;

            if ((vRectItem.Width > vWidth) && (!vLineFirst))  // 当前行剩余宽度放不下且不是行首
            {
                // 偏移到下一行
                FinishLine(aItemNo, aLastDrawItemNo, vWidth);
                aPos.X     = aFmtLeft;
                aPos.Y     = DrawItems[aLastDrawItemNo].Rect.Bottom;
                vLineFirst = true;  // 作为行首
            }

            // 当前行空余宽度能放下或放不下但已经是行首了
            vRect.Left   = aPos.X;
            vRect.Top    = aPos.Y;
            vRect.Right  = vRect.Left + vRectItem.Width;
            vRect.Bottom = vRect.Top + vRectItem.Height + Style.LineSpaceMin;
            NewDrawItem(aItemNo, aOffset, 1, vRect, vParaFirst, vLineFirst, ref aLastDrawItemNo);

            vRemainderWidth = aFmtRight - vRect.Right;  // 放入后的剩余量
        }
Exemplo n.º 3
0
        /// <summary> 转换指定Item指定Offs格式化为DItem </summary>
        /// <param name="AItemNo">指定的Item</param>
        /// <param name="AOffset">指定的格式化起始位置</param>
        /// <param name="AContentWidth">当前Data格式化宽度</param>
        /// <param name="APageContenBottom">当前页格式化底部位置</param>
        /// <param name="APos">起始位置</param>
        /// <param name="ALastDNo">起始DItemNo前一个值</param>
        /// <param name="vPageBoundary">数据页底部边界</param>
        private void FormatItemToDrawItems(int aItemNo, int aOffset, int aFmtLeft, int aFmtRight, int aContentWidth, ref POINT aPos, ref int aLastDrawItemNo)
        {
            if (!Items[aItemNo].Visible)
            {
                return;
            }

            bool             vParaFirst = false, vLineFirst = false;
            HCCustomRectItem vRectItem = null;
            string           vText     = "";
            RECT             vRect     = new RECT();

            int          vRemainderWidth = 0;
            HCCustomItem vItem           = Items[aItemNo];
            HCParaStyle  vParaStyle      = Style.ParaStyles[vItem.ParaNo];

            if (vItem.ParaFirst && (aOffset == 1))
            {
                vParaFirst = true;
                vLineFirst = true;
                aPos.X    += vParaStyle.FirstIndentPix;
            }
            else  // 非段第1个
            {
                vParaFirst = false;
                vLineFirst = (aPos.X == aFmtLeft) && (DrawItems[aLastDrawItemNo].Width != 0);
            }

            if (!vItem.Visible)  // 不显示的Item
            {
                vRect.Left   = aPos.X;
                vRect.Top    = aPos.Y;
                vRect.Right  = vRect.Left;
                vRect.Bottom = vRect.Top + 5;
                NewDrawItem(aItemNo, aOffset, vItem.Length, vRect, vParaFirst, vLineFirst, ref aLastDrawItemNo);
            }
            else
            if (vItem.StyleNo < HCStyle.Null)
            {
                vRectItem = vItem as HCCustomRectItem;
                DoFormatRectItemToDrawItem(vRectItem, aItemNo, aFmtLeft, aContentWidth, aFmtRight, aOffset,
                                           vParaFirst, ref aPos, ref vRect, ref vLineFirst, ref aLastDrawItemNo, ref vRemainderWidth);
            }
            else  // 文本
            {
                CalcItemFormatHeigh(vItem);
                vRemainderWidth = aFmtRight - aPos.X;

                if (aOffset != 1)
                {
                    vText = vItem.Text.Substring(aOffset - 1, vItem.Length - aOffset + 1);
                }
                else
                {
                    vText = vItem.Text;
                }

                if (vText == "")
                {
                    vRect.Left   = aPos.X;
                    vRect.Top    = aPos.Y;
                    vRect.Right  = vRect.Left;
                    vRect.Bottom = vRect.Top + FItemFormatHeight;  //DefaultCaretHeight;
                    vParaFirst   = true;
                    vLineFirst   = true;
                    NewDrawItem(aItemNo, aOffset, 0, vRect, vParaFirst, vLineFirst, ref aLastDrawItemNo);
                    vParaFirst = false;
                }
                else  // 非空Item
                {
                    int vItemLen = vText.Length;
                    if (vItemLen > 38347922)
                    {
                        throw new Exception(HC.HCS_EXCEPTION_STRINGLENGTHLIMIT);
                    }

                    int[] vCharWidths = new int[vItemLen];

                    int[] vCharWArr = null;
                    int   viLen     = vItemLen;
                    if (viLen > FormatTextCut)
                    {
                        vCharWArr = new int[FormatTextCut];
                    }

                    int  vIndex = 0, viBase = 0;
                    SIZE vSize = new SIZE();
                    while (viLen > FormatTextCut)
                    {
                        Style.TempCanvas.GetTextExtentExPoint(vText.Substring(vIndex, FormatTextCut), FormatTextCut, vCharWArr, ref vSize);  // 超过65535数组元素取不到值
                        for (int i = 0; i <= FormatTextCut - 1; i++)
                        {
                            vCharWidths[vIndex + i] = vCharWArr[i] + viBase;
                        }

                        viLen  -= FormatTextCut;
                        vIndex += FormatTextCut;
                        viBase  = vCharWidths[vIndex - 1];
                    }

                    vCharWArr = new int[viLen];
                    Style.TempCanvas.GetTextExtentExPoint(vText.Substring(vIndex, viLen), viLen, vCharWArr, ref vSize);  // 超过65535数组元素取不到值


                    for (int i = 0; i <= viLen - 1; i++)
                    {
                        vCharWidths[vIndex + i] = vCharWArr[i] + viBase;
                    }

                    //SetLength(vCharWArr, 0);
                    DoFormatTextItemToDrawItems(vItem, aOffset, vText, 1, aFmtRight - aPos.X, 0, aItemNo, vItemLen, aFmtLeft, aContentWidth, aFmtRight, vCharWidths,
                                                ref vParaFirst, ref vLineFirst, ref aPos, ref vRect, ref vRemainderWidth, ref aLastDrawItemNo);
                    //SetLength(vCharWidths, 0);
                }
            }

            // 计算下一个的位置
            if (aItemNo == Items.Count - 1)
            {
                FinishLine(aItemNo, aLastDrawItemNo, vRemainderWidth);
            }
            else  // 不是最后一个,则为下一个Item准备位置
            {
                if (Items[aItemNo + 1].ParaFirst)
                {
                    FinishLine(aItemNo, aLastDrawItemNo, vRemainderWidth);
                    // 偏移到下一行顶端,准备另起一行
                    aPos.X = 0;
                    aPos.Y = DrawItems[aLastDrawItemNo].Rect.Bottom;  // 不使用 vRect.Bottom 因为如果行中间有高的,会修正其bottom
                }
                else  // 下一个不是段起始
                {
                    aPos.X = vRect.Right;  // 下一个的起始坐标
                }
            }
        }
Exemplo n.º 4
0
        public bool InsertAnnotate(string aTitle, string aText)
        {
            bool vResult = false;

            if (Items[SelectInfo.StartItemNo].StyleNo < HCStyle.Null && SelectInfo.StartItemOffset == HC.OffsetInner)
            {
                Undo_New();

                HCCustomRectItem vRectItem = Items[SelectInfo.StartItemNo] as HCCustomRectItem;
                if (vRectItem.MangerUndo)
                {
                    UndoAction_ItemSelf(SelectInfo.StartItemNo, HC.OffsetInner);
                }
                else
                {
                    UndoAction_ItemMirror(SelectInfo.StartItemNo, HC.OffsetInner);
                }

                vResult = (Items[SelectInfo.StartItemNo] as HCCustomRectItem).InsertAnnotate(aTitle, aText);

                int vFormatFirstDrawItemNo = -1, vFormatLastItemNo = -1;
                if (vRectItem.IsFormatDirty)
                {
                    GetFormatRange(ref vFormatFirstDrawItemNo, ref vFormatLastItemNo);
                    FormatPrepare(vFormatFirstDrawItemNo, vFormatLastItemNo);
                    ReFormatData(vFormatFirstDrawItemNo, vFormatLastItemNo);
                }
                else
                {
                    this.FormatInit();
                }

                return(vResult);
            }
            else
            {
                if (!CanEdit())
                {
                    return(false);
                }

                this.Style.States.Include(HCState.hosBatchInsert);  // 批量插入防止插入1个起始触发取配对时,结束还没插入呢
                try
                {
                    int vIncCount = 0, vFormatFirstDrawItemNo = -1, vFormatLastItemNo = -1;
                    Undo_New();

                    if (this.SelectExists())
                    {
                        vFormatFirstDrawItemNo = GetFormatFirstDrawItem(SelectInfo.StartItemNo, SelectInfo.StartItemOffset);
                        vFormatLastItemNo      = GetParaLastItemNo(SelectInfo.EndItemNo);
                    }
                    else
                    {
                        GetFormatRange(SelectInfo.StartItemNo, 1, ref vFormatFirstDrawItemNo, ref vFormatLastItemNo);
                    }

                    FormatPrepare(vFormatFirstDrawItemNo, vFormatLastItemNo);
                    FNextID++;

                    // 插入尾
                    HCAnnotateItem vAnnotateItem = new HCAnnotateItem(this);
                    vAnnotateItem.MarkType      = MarkType.cmtEnd;
                    vAnnotateItem.ID            = FNextID;
                    vAnnotateItem.Content.Title = aTitle;
                    vAnnotateItem.Content.Text  = aText;
                    if (SelectInfo.EndItemNo >= 0) // 有选中结束item
                    {
                        vIncCount = InsertAnnotateByOffset(vAnnotateItem, SelectInfo.EndItemNo, SelectInfo.EndItemOffset);
                    }
                    else
                    {
                        vIncCount = InsertAnnotateByOffset(vAnnotateItem, SelectInfo.StartItemNo, SelectInfo.StartItemOffset);
                    }

                    // 插入头
                    vAnnotateItem          = new HCAnnotateItem(this);
                    vAnnotateItem.MarkType = MarkType.cmtBeg;
                    vAnnotateItem.ID       = FNextID;
                    vIncCount = vIncCount + InsertAnnotateByOffset(vAnnotateItem, SelectInfo.StartItemNo, SelectInfo.StartItemOffset);
                    ReFormatData(vFormatFirstDrawItemNo, vFormatLastItemNo + vIncCount, vIncCount);
                }
                finally
                {
                    this.Style.States.Exclude(HCState.hosBatchInsert);
                }

                Style.UpdateInfoRePaint();
                Style.UpdateInfoReCaret();
                // 因上面批量屏蔽了取当前位置域的功能,所以都插完后,取一下当前位置域情况
                ReSetSelectAndCaret(SelectInfo.StartItemNo);
                return(true);
            }
        }