Beispiel #1
0
        /// <summary>
        /// create list of ShowLiteralItem and ShowFieldItem from the list of orders of
        /// a WriteToDisplay command.
        /// </summary>
        /// <param name="WtdCommand"></param>
        /// <param name="LogList"></param>
        /// <returns></returns>
        public static Tuple <ShowItemList, OneRowCol> BuildShowItemList(
            this WriteToDisplayCommand WtdCommand, ScreenDim ScreenDim,
            TelnetLogList LogList)
        {
            var       itemList  = new ShowItemList();
            IRowCol   curRowCol = new ZeroRowCol(0, 0);
            OneRowCol caret     = null;

            foreach (var order in WtdCommand.OrderList)
            {
                bool newGroup = false;
                if ((order.OrderCode == WtdOrder.SetBufferAddress) ||
                    (order.OrderCode == WtdOrder.StartHeader))
                {
                    newGroup = true;
                }
                LogList.AddItem(Direction.Read, order.ToString(), newGroup);
                LogList.AddItem(Direction.Read, order.ToHexString());

                if (order is TextDataOrder)
                {
                    var tdo = order as TextDataOrder;
                    var s1  = tdo.ShowText;
                    if ((tdo.AttrByte != null) || (s1.Length > 0) ||
                        (tdo.TailAttrByte != null))
                    {
                        var litItem = new ShowLiteralItem(
                            (ZeroRowCol)curRowCol, tdo.AttrByte, s1, tdo.TailAttrByte);
                        litItem.tdo_Length = s1.Length;

                        itemList.Add(litItem);
                        curRowCol = curRowCol.Advance(litItem.ItemLength());
                    }
                }

                else if (order.OrderCode == WtdOrder.StartField)
                {
                    var sfo      = order as StartFieldOrder;
                    var lx       = sfo.LL_Length;
                    var attrByte = sfo.AttrByte;

                    var fldItem = new ShowFieldItem((ZeroRowCol)curRowCol, sfo.AttrByte,
                                                    ShowUsage.Both, ShowDtyp.Char, lx);
                    fldItem.IsMonocase   = sfo.IsMonocase;
                    fldItem.sfo_FCW      = sfo.FCW_Bytes;
                    fldItem.sfo_FFW      = sfo.FFW_Bytes;
                    fldItem.sfo_Length   = sfo.LL_Length;
                    fldItem.IsNonDisplay = sfo.IsNonDisplay;

                    // field is non display.
                    //        if ((attrByte & 0x07) == 0x07)
                    //        {
                    //          fldItem.IsNonDisplay = true;
                    //        }

                    itemList.Add(fldItem);
                    curRowCol = curRowCol.Advance(1); // advance because of attrbyte.
                }

                else if (order.OrderCode == WtdOrder.SetBufferAddress)
                {
                    var sba = order as SetBufferAddressOrder;
                    curRowCol = sba.GetRowCol(ScreenDim).ToZeroRowCol();
                }

                else if (order.OrderCode == WtdOrder.InsertCursor)
                {
                    var ico = order as InsertCursorOrder;
                    caret = ico.RowCol;
                }

                else if (order.OrderCode == WtdOrder.RepeatToAddress)
                {
                    var rao = order as RepeatToAddressOrder;
                    var s1  = rao.RepeatShowText((ZeroRowCol)curRowCol);

                    var litItem = new ShowLiteralItem((ZeroRowCol)curRowCol, s1);
                    litItem.rao_RepeatTextByte = rao.RepeatTextByte;
                    litItem.rao_ToRowCol       = rao.RowCol;

                    itemList.Add(litItem);
                    curRowCol = curRowCol.Advance(s1.Length);
                }

                else if (order.OrderCode == WtdOrder.EraseToAddress)
                {
                    var eao     = order as EraseToAddressOrder;
                    var lx      = eao.EraseLength((ZeroRowCol)curRowCol);
                    var s1      = (" ").Repeat(lx);
                    var litItem = new ShowLiteralItem((ZeroRowCol)curRowCol, s1);
                    litItem.rao_RepeatTextByte = 0x00;
                    litItem.rao_ToRowCol       = eao.RowCol;

                    itemList.Add(litItem);
                    curRowCol = curRowCol.Advance(s1.Length);
                }
            }
            return(new Tuple <ShowItemList, OneRowCol>(itemList, caret));
        }
Beispiel #2
0
        /// <summary>
        /// apply the orders of the WriteToDisplay command to the screen content
        /// block.
        /// </summary>
        /// <param name="ApplyMaster"></param>
        /// <param name="wtdCmd"></param>
        /// <returns></returns>
        public static ScreenContent Apply(
            this ScreenContent ApplyMaster, WriteToDisplayCommand wtdCmd)
        {
            IRowCol curRowCol = new ZeroRowCol(0, 0, ApplyMaster);
            var     master    = ApplyMaster;

            foreach (var order in wtdCmd.OrderList)
            {
                if (order is SetBufferAddressOrder)
                {
                    var sba = order as SetBufferAddressOrder;
                    curRowCol = sba.GetRowCol(master.ScreenDim).ToZeroRowCol().ToContentRelative(master);
                }

                // screen position is out of bounds. Do not place text or field onto the
                // screen at an invalid position.
                else if (curRowCol.ColNum >= master.ScreenDim.Width)
                {
                }

                else if (order is StartFieldOrder)
                {
                    var sfo          = order as StartFieldOrder;
                    var contentField = master.ApplyStartFieldOrder(curRowCol, sfo);
                    curRowCol = curRowCol.Advance(1);
                }

                else if (order is RepeatToAddressOrder)
                {
                    var rao       = order as RepeatToAddressOrder;
                    var lx        = rao.RepeatLength((ZeroRowCol)curRowCol.ToParentRelative(master));
                    var textBytes = rao.GetRepeatTextBytes(lx);
                    master.ApplyTextBytes(curRowCol, textBytes);
                    curRowCol = curRowCol.Advance(lx);
                }

                else if (order is TextDataOrder)
                {
                    var tdo = order as TextDataOrder;
                    master.ApplyTextBytes(curRowCol, tdo.RawBytes);
                    curRowCol = tdo.Advance(curRowCol);
                }

                else if (order is InsertCursorOrder)
                {
                    var ico = order as InsertCursorOrder;
                    master.CaretRowCol = ico.RowCol;
                }

                else if (order is EraseToAddressOrder)
                {
                    var eao       = order as EraseToAddressOrder;
                    var lx        = eao.EraseLength((ZeroRowCol)curRowCol.ToParentRelative(master));
                    var textBytes = ((byte)0x00).Repeat(lx);
                    master.ApplyTextBytes(curRowCol, textBytes);
                    curRowCol = curRowCol.Advance(lx);
                }

                // WriteStructuredField order. used to create a window ScreenContent
                // within the main screenContent.
                else if (order is CreateWindowStructuredField)
                {
                    var sfo = order as CreateWindowStructuredField;

                    // create the window as a ScreenContent block onto itself. All future
                    // WTD orders are applied to the window screen content.
                    var windowMaster = new WindowScreenContent(
                        master,
                        sfo.WindowDim, (ZeroRowCol)curRowCol);

                    // store the index of this new child window as the index of the
                    // "current window" SCB within the parent SCB.
                    master.CurrentChildIndex = master.Children.Length - 1;

                    // the window is now the current SCB.
                    master = windowMaster;

                    // reset the current rowCol to position 0,0 within the window.
                    curRowCol = new ZeroRowCol(0, 0, master);
                }
            }

            return(master);
        }
        /// <summary>
        /// create visual items from the show items and place those visual items on the
        /// canvase.
        /// </summary>
        /// <param name="ShowItemList"></param>
        private OneRowCol PaintScreen_Actual(
            WriteToDisplayCommand WTD_command, TelnetLogList LogList = null)
        {
            IRowCol   curRowCol = new ZeroRowCol(0, 0);
            OneRowCol caret     = null;

            foreach (var order in WTD_command.OrderList)
            {
                if (LogList != null)
                {
                    LogList.AddItem(Direction.Read, "PaintScreen. " + order.ToString());
                }

                if (order is TextDataOrder)
                {
                    var tdo = order as TextDataOrder;
                    if (tdo.IsEmpty() == false)
                    {
                        PaintScreen_ApplyTextDataOrder(tdo, curRowCol);
                    }
                    curRowCol = tdo.Advance(curRowCol);
                }

                else if (order is SetBufferAddressOrder)
                {
                    var sba = order as SetBufferAddressOrder;
                    curRowCol = sba.GetRowCol(this.ScreenDim).ToZeroRowCol();
                }

                else if (order.OrderCode == WtdOrder.InsertCursor)
                {
                    var ico = order as InsertCursorOrder;
                    caret = ico.RowCol;
                }

                else if (order is StartFieldOrder)
                {
                    var sfo = order as StartFieldOrder;
                    {
                        var showText = new String(' ', sfo.LL_Length);
                        var vtb      = new VisualTextBlock(
                            showText, (ZeroRowCol)curRowCol, sfo.AttrByte,
                            this.CanvasDefn.CharBoxDim, this.CanvasDefn.KernDim,
                            this.CanvasDefn.FontDefn);
                        var iMore = vtb as IVisualItemMore;
                        var node  = iMore.InsertIntoVisualItemsList(this.VisualItems);
                        iMore.AddToCanvas(this);

                        vtb.SetupFieldItem(
                            sfo, this.CanvasDefn.CharBoxDim, this.CanvasDefn.KernDim);
                    }
                    curRowCol = curRowCol.Advance(1);
                }

                else if (order is RepeatToAddressOrder)
                {
                    var rao = order as RepeatToAddressOrder;
                    this.VisualItems.ApplyRepeatToAddressOrder(curRowCol, rao, this);
                    var lx = rao.RepeatLength((ZeroRowCol)curRowCol);
                    curRowCol = curRowCol.Advance(lx);
                }

                else if (order is EraseToAddressOrder)
                {
                    var eao = order as EraseToAddressOrder;
                    this.VisualItems.ApplyEraseToAddressOrder(curRowCol, eao, this);
                    var lx = eao.EraseLength((ZeroRowCol)curRowCol);
                    curRowCol = curRowCol.Advance(lx);
                }
            }
            return(caret);
        }