Exemple #1
0
        /// <summary>
        /// return the ContentField with a textbyte that covers the specified rowcol
        /// location.
        /// </summary>
        /// <param name="ix"></param>
        /// <returns></returns>
        public ContentField GetContentField(IRowCol RowCol)
        {
            ContentField getField = null;
            int          ix       = ToContentIndex(RowCol);

            // look prior to the location, looking for that closest field.
            while (ix > 0)
            {
                ix -= 1;
                var textByte = this.ContentArray[ix];
                if (textByte.IsAttrByte( ))
                {
                    ContentItemBase contentItem = null;
                    var             rowCol      = ix.ToZeroRowCol(this.ScreenDim);
                    var             rc          = this.FieldDict.TryGetValue(rowCol, out contentItem);

                    // attr byte is start of a field.
                    if ((rc == true) && (contentItem is ContentField))
                    {
                        var field = contentItem as ContentField;

                        var fieldRange = new RowColRange(field.RowCol.AdvanceRight( ), field.LL_Length);
                        if (fieldRange.Contains(RowCol))
                        {
                            getField = field;
                            break;
                        }
                    }
                }
            }

            return(getField);
        }
Exemple #2
0
        public static ContentItemBase GetContentItem(this ScreenContent Content, IScreenLoc loc)
        {
            ContentItemBase foundItem = null;

            foreach (var contentItem in Content.ContentItems())
            {
                var itemLoc = contentItem.RowCol as IScreenLoc;
                var range   = new ScreenLocRange(
                    itemLoc, contentItem.GetItemLength(Content), Content.ScreenDim);
                if (range.Contains(loc))
                {
                    foundItem = contentItem;
                    break;
                }
            }
            return(foundItem);
        }
Exemple #3
0
        /// <summary>
        /// return the sequence of fields that start within the rowcol range of the
        /// content table.
        /// </summary>
        /// <param name="Range"></param>
        /// <returns></returns>
        public IEnumerable <ContentField> ContentFields(RowColRange Range)
        {
            int             ix          = 0;
            ContentItemBase contentItem = null;

            foreach (var b1 in ContentBytes(Range))
            {
                if (b1.IsAttrByte( ))
                {
                    var rowCol = Range.From.Advance(ix) as ZeroRowCol;
                    var rc     = this.FieldDict.TryGetValue(rowCol, out contentItem);
                    if ((rc == true) && (contentItem is ContentField))
                    {
                        yield return(contentItem as ContentField);
                    }
                }
                ix += 1;
            }
            yield break;
        }
Exemple #4
0
        public IEnumerable <ContentItemBase> ContentItems()
        {
            int ix         = -1;
            var blankBytes = new byte[] { 0x00, 0x40 };

            while (true)
            {
                ix += 1;
                if (ix >= this.ContentArray.Length)
                {
                    break;
                }

                // advance to next non blank.
                ix = this.ContentArray.IndexOfNotEqual(ix, blankBytes);
                if (ix == -1)
                {
                    break;
                }
                var curByte = this.ContentArray[ix];

                // not an attribute byte. process bytes up until an attr byte as
                // ContentText.
                if (curByte.IsAttrByte() == false)
                {
                    var bx      = ix;
                    var rv      = ContentArray_ScanUntilAttrByte(ix);
                    var textBuf = rv.Item1;
                    var abIx    = rv.Item2;
                    if (textBuf.Length > 0)
                    {
                        // only if the text bytes are not all blanks.
                        var fx = textBuf.IndexOfNotEqual(0, blankBytes);
                        if (fx != -1)
                        {
                            var rowcol      = ix.ToZeroRowCol(this.ScreenDim);
                            var contentText = new ContentText(rowcol, null, textBuf.Length, null);
                            yield return(contentText);
                        }
                    }

                    // setup ix for next iteration of the loop.
                    if (abIx == -1)
                    {
                        ix = this.ContentArray.Length;
                    }
                    else
                    {
                        ix = abIx - 1;
                    }
                    continue;
                }

                // Got attr byte. Check that start of a field defined in the FieldDict.
                {
                    ContentItemBase contentItem = null;
                    var             rowCol      = ix.ToZeroRowCol(this.ScreenDim);
                    var             rc          = this.FieldDict.TryGetValue(rowCol, out contentItem);

                    // attr byte is start of a field.
                    if ((rc == true) && (contentItem is ContentField))
                    {
                        var contentField = contentItem as ContentField;
                        contentField.LoadContents(this);
                        ix += 1;               // advance past attr byte.
                        ix  = (ix + contentField.LL_Length) - 1;
                        yield return(contentField);

                        continue;
                    }
                }

                // attribute byte is not a field. Look for whitespace immed after the attr
                // byte.
                {
                    var abIx = ix;
                    if (curByte == 0x20)
                    {
                        var fx = this.ContentArray.IndexOfNotEqual(ix + 1, blankBytes);

                        // nothing but whitespace after the attr byte. Setup ix so next iter will
                        // be EOF.
                        if (fx == -1)
                        {
                            ix = this.ContentArray.Length;
                            continue;
                        }

                        // blanks until another attr byte. skip the current attr and the
                        // whitespace that follows.
                        else if (this.ContentArray[fx].IsAttrByte() == true)
                        {
                            ix = fx - 1;
                            continue;
                        }
                    }

                    // got a text char to display as ContentText.
                    {
                        int textStart  = abIx + 1;
                        var rv         = ContentArray_ScanUntilAttrByte(textStart);
                        var rowCol     = abIx.ToZeroRowCol(this.ScreenDim);
                        var textLength = rv.Item1.Length;

                        // the end of content text attr byte is x'20'. Treat as tail attr byte.
                        int?tailAttrByteIx = null;
                        int nextIx         = rv.Item2;
                        if ((nextIx != -1) && (rv.Item3 == 0x20))
                        {
                            var nextByte = ContentArray_NextNonZeroByte(nextIx + 1);
                            if ((nextByte == null) || (nextByte.Value.IsAttrByte( ) == true))
                            {
                                tailAttrByteIx = nextIx;
                                nextIx        += 1;
                            }
                        }

                        // no attribute found. trim blanks from byte buffer.
                        if (nextIx == -1)
                        {
                            var byteBuf = rv.Item1;
                            var fx      = byteBuf.IndexOfLastNotEqual(blankBytes);
                            if (fx == -1)
                            {
                                textLength = 0;
                            }
                            else
                            {
                                textLength = fx + 1;
                            }
                        }

                        // return the text constant.
                        var contentText = new ContentText(
                            rowCol, this.ContentArray[abIx], textLength, tailAttrByteIx);
                        yield return(contentText);

                        if (nextIx == -1)
                        {
                            break;
                        }
                        ix = nextIx - 1;
                    }
                }
            }

            yield break;
        }