public static Tuple <bool, OneRowCol> PaintCanvas( this WriteToDisplayCommand WTD_command, ItemCanvas ItemCanvas, bool EraseScreen = true, TelnetLogList LogList = null ) { OneRowCol caret = null; bool drawDone = false; caret = ItemCanvas.PaintScreen(WTD_command, EraseScreen, LogList); drawDone = true; return(new Tuple <bool, OneRowCol>(drawDone, caret)); }
public OneRowCol PaintScreen( WriteToDisplayCommand WTD_command, bool Erase = true, TelnetLogList LogList = null) { if (Erase == true) { this.EraseScreen(); if (LogList != null) { LogList.AddItem(Direction.Read, "PaintScreen. EraseScreen."); } } this.ShowItemList = null; var caret = PaintScreen_Actual(WTD_command, LogList); return(caret); }
/// <summary> /// no longer used. called WorkstationCommandListExt.ProcessAndPaint, which /// itself is not used. /// </summary> /// <param name="VisualItems"></param> /// <param name="Caret"></param> /// <returns></returns> public static byte[] BuildSaveScreenResponse( ScreenVisualItems VisualItems, CanvasPositionCursor Caret) { var ra = new ByteArrayBuilder(); // data stream header. { var buf = DataStreamHeader.Build(50, TerminalOpcode.SaveScreen, 0, 0); ra.Append(buf); } // restore screen workstation command. { var cmd = new RestoreScreenCommand(); ra.Append(cmd.ToBytes()); } // clear unit command. { var cmd = new ClearUnitCommand(); ra.Append(cmd.ToBytes()); } // WTD command. { var ordersByteStream = VisualItems.BuildOrderStream(Caret); var buf = WriteToDisplayCommand.Build(0x00, 0x18, ordersByteStream); ra.Append(buf); } // update length of response data stream. { var wk = new ByteArrayBuilder(); wk.AppendBigEndianShort((short)ra.Length); ra.CopyToBuffer(wk.ToByteArray(), 0); } // IAC EOR { ra.Append(EOR_Command.Build()); } return(ra.ToByteArray()); }
public static IEnumerable <string> Print_WTD_Orders(this WriteToDisplayCommand wtdCmd) { var lines = new List <string>(); var lb = new BlankFillLineBuilder(); var item = new PrintItem(); { var titleText = "5250 Write To Display Workstation Command Orders."; lines.Add(titleText.PadCenter(80)); var chd = PrintColumnHeading(); lines.AddRange(chd); } foreach (var order in wtdCmd.OrderList) { if (order is SetBufferAddressOrder) { if (item.ItemType != null) { item = PrintAndAdvance(lines, item); } var sba = order as SetBufferAddressOrder; item = new PrintItem(sba); { var item2 = new PrintItem(sba); item2.ItemType = ReportItemType.sba; PrintDetailLine(lines, item2); } } else if (order is StartFieldOrder) { item = CheckPrintItem(lines, item); var sof = order as StartFieldOrder; item.ItemType = ReportItemType.Field; item.ItemLgth = sof.LL_Length; item.AttrByte = sof.AttrByte; item.ffw = sof.FFW_Bytes.Concat(sof.FCW_Bytes); } else if (order is RepeatToAddressOrder) { var ra = order as RepeatToAddressOrder; item = CheckPrintItem(lines, item); item.ItemType = ReportItemType.RepeatToAddress; // the length covered by the repeat order. From the current screen location // to the row/col of the RA order. item.ItemLgth = item.RowCol.DistanceInclusive(ra.RowCol); item.ItemText = ra.RepeatPrintableChar; item = PrintAndAdvance(lines, item); } else if (order is EraseToAddressOrder) { var ea = order as EraseToAddressOrder; item = CheckPrintItem(lines, item); item.ItemType = ReportItemType.EraseToAddress; // the length covered by the repeat order. From the current screen location // to the row/col of the EA order. item.ItemLgth = item.RowCol.DistanceInclusive(ea.RowCol); item.ItemText = ((string)"00 ").Repeat(item.ItemLgth.Value); item = PrintAndAdvance(lines, item); } else if (order is TextDataOrder) { var td = order as TextDataOrder; { var s1 = td.PrintableText; if (s1 != null) { item.ItemText = s1; } if (item.AttrByte == null) { item.AttrByte = td.AttrByte; } if (item.ItemType == null) { if (td.DisplayText != null) { item.ItemLgth = td.TextLength; } item.ItemType = ReportItemType.Literal; } } item = PrintAndAdvance(lines, item); } else if (order is CreateWindowStructuredField) { var sfo = order as CreateWindowStructuredField; item = CheckPrintItem(lines, item); var sof = order as StartFieldOrder; item.ItemType = ReportItemType.CrtWdw; item.WindowDim = new ScreenDim(sfo.NumRow, sfo.NumCol); item = PrintAndAdvance(lines, item); } } if (item.HasPrintableContent()) { PrintAndAdvance(lines, item); } return(lines); }
/// <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 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)); }
/// <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); }