/// <summary> /// the inclusive length of the range. /// </summary> /// <returns></returns> public int GetLength(ScreenDim Dim) { int lx = 0; if (To.RowNum == From.RowNum) { lx = To.ColNum - From.ColNum + 1; } else { var from = From.ToZeroBased(); var to = To.ToZeroBased(); int row = From.RowNum; int col = From.ColNum; while (row < to.RowNum) { lx = lx + (Dim.Width - col); col = 0; row += 1; } lx += (to.ColNum - col + 1); } return(lx); }
/// <summary> /// calc the column distance from Loc1 to Loc2. Distance includes the location /// itself. /// </summary> /// <param name="Loc1"></param> /// <param name="Loc2"></param> /// <param name="Dim"></param> /// <returns></returns> public static int DistanceInclusive(this IRowCol Loc1, IRowCol Loc2, ScreenDim Dim) { // ensure loc1 is before loc2. var loc1 = Loc1; var loc2 = Loc2; if (loc1.IsAfter(loc2)) { loc1 = Loc2; loc2 = Loc1; } // number of rows difference. int rowDiff = loc2.RowNum - loc1.RowNum; // number of colums. if (loc2.ColNum < loc1.ColNum) { rowDiff -= 1; loc2.ColNum += Dim.Width; } int colDiff = loc2.ColNum - loc1.ColNum; int lgth = (rowDiff * Dim.Width) + colDiff + 1; return(lgth); }
public static ZeroRowCol ToZeroRowCol(this int ix, ScreenDim Dim) { int colNum = 0; int rowNum = Math.DivRem(ix, Dim.Width, out colNum); var rowCol = new ZeroRowCol(rowNum, colNum, Dim); return(rowCol); }
public ZeroRowCol( int RowNum, int ColNum, ScreenDim Dim, RowColRelative RowColRelative = RowColRelative.Parent, CharPoint ContentStart = null) : base(RowNum, ColNum, LocationFrame.ZeroBased, Dim, RowColRelative, ContentStart) { }
public CanvasWindow(ScreenDim WindowDim) { this.WindowDim = WindowDim; InitializeComponent(); this.Closed += CanvasWindow_Closed; this.Loaded += CanvasWindow_Loaded; this.PreviewKeyDown += CanvasWindow_PreviewKeyDown; }
public ToThread( ExtendedManualResetEvent ShutdownFlag, TcpClient Client, ScreenDim ScreenDim) : base(ShutdownFlag) { this.Client = Client; this.InputQueue = new ConcurrentMessageQueue(); this.ConnectionFailedEvent = new AutoResetEvent(false); this.LogList = new TelnetLogList("To"); }
public ScreenLocRange(IScreenLoc From, int Length, ScreenDim Dim) { this.From = From; if (Length == 0) { this.To = From; } else { this.To = From.Advance(Length - 1, Dim); } }
public MasterThread( ExtendedManualResetEvent ShutdownFlag, ExtendedManualResetEvent ConnectionFailedEvent, ScreenDim ScreenDim, ItemCanvas TelnetCanvas) : base(ShutdownFlag) { this.ContentOdom = new ConcurrentOdom(); this.InputQueue = new ConcurrentMessageQueue(); this.ConnectionFailedEvent = ConnectionFailedEvent; this.ScreenDim = ScreenDim; this.TelnetCanvas = TelnetCanvas; this.LogList = new TelnetLogList("Master"); }
public FromThread( ExtendedManualResetEvent ShutdownFlag, TcpClient Client, ConcurrentMessageQueue TelnetQueue, SessionSettings Settings, ScreenDim ScreenDim) : base(ShutdownFlag) { this.Client = Client; this.InputQueue = new ConcurrentMessageQueue(); this.TelnetQueue = TelnetQueue; this.ConnectionFailedEvent = new ExtendedManualResetEvent(false); this.SessionSettings = Settings; this.LogList = new TelnetLogList("From"); }
public static ScreenLocRange GetLocRange(this IScreenItem item, ScreenDim Dim) { ScreenLocRange range = null; if ( item is IScreenAtomic ) { var atomicItem = item as IScreenAtomic; range = new ScreenLocRange(item.ScreenLoc, atomicItem.Length, Dim); } else if (item is IScreenSection) { var sectionItem = item as IScreenSection; range = sectionItem.ToRepeatRange(); } return range; }
public static ScreenDim GetPrimaryScreenResolution() { var screen = System.Windows.Forms.Screen.AllScreens; ScreenDim dimScreen = new ScreenDim(screen[0].Bounds.Height, screen[0].Bounds.Width); //Nel caso ce ne fosse uno foreach (var sc in screen) { if (sc.Primary) { dimScreen = new ScreenDim(sc.Bounds.Height, sc.Bounds.Width); return(dimScreen); } } return(dimScreen); }
public ScreenContent( ScreenContent Parent, ScreenDim ScreenDim, ConcurrentOdom ContentOdom) : this(ContentOdom) { this.ScreenDim = ScreenDim; this.ContentArray = new byte[4000]; this.ContentArrayLx = this.ScreenDim.Width * this.ScreenDim.Height; this.FieldDict = new ContentDict(); // add this ScreenContent as a child of the Parent SCB. if (Parent != null) { Parent.AddChild(this); } }
public static IScreenLoc Advance(this IScreenLoc Loc, int Length, ScreenDim Dim) { int col = Loc.ColNum + Length; int row = Loc.RowNum; // adjust to zero based. if (Loc.LocationFrame == LocationFrame.OneBased) { col -= 1; row -= 1; } // negative advance and column off the charts to the left. while (col < 0) { col += Dim.Width; row -= 1; if (row < 0) { row = Dim.Height - 1; } } // positive advance and column out of bounds to the right. while (col >= Dim.Width) { col -= Dim.Width; row += 1; if (row >= Dim.Height) { row = Dim.Height - 1; } } // back to one based. if (Loc.LocationFrame == LocationFrame.OneBased) { col += 1; row += 1; } return(Loc.NewInstance(row, col)); }
public static ScreenAtomic FindFieldItem( this IEnumerable <ScreenAtomic> List, IScreenLoc ScreenLoc, int Length) { ScreenAtomic found = null; var dim = new ScreenDim(24, 80); var range = new ScreenLocRange(ScreenLoc, Length, dim); foreach (var item in List) { if (item.ItemType == ShowItemType.Field) { if (item.ScreenLocRange.CompletelyContains(range) == true) { found = item; break; } } } return(found); }
protected RowColBase( int RowNum, int ColNum, LocationFrame LocationFrame, ScreenDim Dim, RowColRelative RowColRelative, CharPoint ContentStart) { this.RowNum = RowNum; this.ColNum = ColNum; this.Dim = Dim; this.LocationFrame = LocationFrame; this.RowColRelative = RowColRelative; this.ContentStart = ContentStart; if (LocationFrame == LocationFrame.OneBased) { this.HorzBounds = new IntPair(1, this.Dim.Width); this.VertBounds = new IntPair(1, this.Dim.Height); } else { this.HorzBounds = new IntPair(0, this.Dim.Width - 1); this.VertBounds = new IntPair(0, this.Dim.Height - 1); } }
/// <summary> /// run the BuildShowItemList method against the first WriteToDisplay command in /// the list of workstation commands. /// </summary> /// <param name="LogList"></param> /// <returns></returns> public static ShowItemList BuildShowItemList( this WorkstationCommandList CommandList, ScreenDim ScreenDim, TelnetLogList LogList) { ShowItemList showItemList = null; OneRowCol caret = null; foreach (var workstationCommand in CommandList) { if (workstationCommand is WriteToDisplayCommand) { var wtdCmd = workstationCommand as WriteToDisplayCommand; TelnetLogList logList = new TelnetLogList(); var rv = wtdCmd.BuildShowItemList(ScreenDim, logList); showItemList = rv.Item1; if (rv.Item2 != null) { caret = rv.Item2; } break; } } return(showItemList); }
public ItemCanvas(System.Windows.Controls.Canvas Canvas, ScreenDim ScreenDim, double FontPointSize, MasterThread MasterThread, PaintThread PaintThread, int ContentNum) { this.Canvas = Canvas; this.CanvasDefn = new CanvasDefn(ScreenDim, FontPointSize); this.CaretLoc = new ZeroRowCol(0, 0); this.VisualItems = new ScreenVisualItems(); this.CanvasCaret = new CanvasCaret(this); this.MasterThread = MasterThread; this.PaintThread = PaintThread; this.HoverBox = new HoverBox(true); this.HoverBox.HoverWindowMouseEnterLeave += HoverBox_HoverWindowMouseEnterLeave; this.HoverBox.HoverWindowChanged += HoverBox_HoverWindowChanged; // the ContentNum of the ScreenContent associated with this ItemCanvas. this.ContentNum = ContentNum; HookUserInputEvents(); // this.HoverTimer = new HoverTimer(650, this); }
static Tuple <ScreenContent, ScreenContent> ProcessClearUnit( this ScreenContent InBaseMaster, ScreenDim ScreenDim, PaintThread PaintThread) { var baseMaster = InBaseMaster; baseMaster = new ScreenContent( null, ScreenDim, baseMaster.ContentOdom); var master = baseMaster.GetWorkingContentBlock(); // post ClearUnit message to paint thread. { var cu = new ClearUnitMessage(master.ContentNum); PaintThread.PostInputMessage(cu); } // mark the screenContent as having ClearUnit applied on it. When the SCB // is sent to the PaintThread code there will clear the TelnetCanvas and // dispose of any window item canvases. // todo: Send ClearUnitMessage to PaintThread. Get rid of DoClearUnit flag. baseMaster.DoClearUnit = true; return(new Tuple <ScreenContent, ScreenContent>(baseMaster, master)); }
protected RowColBase( LocationFrame LocationFrame, ScreenDim Dim, RowColRelative RowNumRelative) { this.RowNum = RowNum; this.ColNum = ColNum; int width = Dim.Width; int height = Dim.Height; this.RowColRelative = RowNumRelative; if (LocationFrame == LocationFrame.OneBased) { this.HorzBounds = new IntPair(1, width); this.VertBounds = new IntPair(1, height); } else { this.HorzBounds = new IntPair(0, width - 1); this.VertBounds = new IntPair(0, height - 1); } // init row and col to values that are out of bounds. this.RowNum = this.VertBounds.a - 1; this.ColNum = this.HorzBounds.a - 1; }
public ScreenUtils() { Screen = GetPrimaryScreenResolution(); }
/// <summary> /// apply the commands of the workstation command list to the screen content /// block. /// </summary> /// <param name="applyMaster"></param> /// <param name="CmdList"></param> /// <param name="ToThread"></param> /// <param name="LogList"></param> /// <returns></returns> public static Tuple <bool, ScreenContent> Apply( this ScreenContent InBaseMaster, WorkstationCommandList CmdList, ToThread ToThread, PaintThread PaintThread, TelnetLogList LogList) { bool wtdApplied = false; var baseMaster = InBaseMaster; var master = baseMaster.GetWorkingContentBlock(); foreach (var cmdBase in CmdList) { if (cmdBase is ClearUnitCommand) { var rv = ProcessClearUnit(baseMaster, baseMaster.ScreenDim, PaintThread); baseMaster = rv.Item1; master = rv.Item2; } // same as ClearUnit. Only signals that a wide screen to be used. else if (cmdBase is ClearUnitAlternateCommand) { var cua = cmdBase as ClearUnitAlternateCommand; // screen size. ScreenDim screenDim; if (cua.RequestByte == 0x00) { screenDim = new ScreenDim(27, 132); } else { screenDim = new ScreenDim(24, 80); } var rv = ProcessClearUnit(baseMaster, screenDim, PaintThread); baseMaster = rv.Item1; master = rv.Item2; } // apply the orders of the WriteToDisplay command. else if (cmdBase is WriteToDisplayCommand) { var curMaster = master.Apply(cmdBase as WriteToDisplayCommand); master = curMaster; wtdApplied = true; } else if (cmdBase is ReadMdtFieldsCommand) { master.HowRead = HowReadScreen.ReadMdt; } // save screen command. Build response, send back to server. else if (cmdBase is SaveScreenCommand) { var msg = new SaveScreenMessage(master.Copy()); ToThread.PostInputMessage(msg); } // read screen command. Build response, send back to server. else if (cmdBase is ReadScreenCommand) { var msg = new ReadScreenMessage(master.Copy()); ToThread.PostInputMessage(msg); } else if (cmdBase is WriteStructuredFieldCommand) { var wsfCmd = cmdBase as WriteStructuredFieldCommand; if (wsfCmd.RequestCode == WSF_RequestCode.Query5250) { var msg = new Query5250ResponseMessage(); ToThread.PostInputMessage(msg); } } else if (cmdBase is WriteSingleStructuredFieldCommand) { } } return(new Tuple <bool, ScreenContent>(wtdApplied, baseMaster)); }
/// <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)); }
public ItemCanvas( System.Windows.Controls.Canvas canvas, double charWidth, double charHeight, ScreenDim ScreenDim, double FontPointSize, PaintThread PaintThread) : this(canvas, ScreenDim, FontPointSize, null, PaintThread, 0) { }
public OneRowCol GetRowCol(ScreenDim ScreenDim) { return(new OneRowCol(RowNum, ColNum, ScreenDim)); }
public CanvasDefn(ScreenDim ScreenDim, double PointSize) { this.ScreenDim = ScreenDim; this.FontDefn = new FontDefn(PointSize); ChangeFontSize(PointSize); }
public WindowScreenContent( ScreenContent Parent, ScreenDim WindowDim, ZeroRowCol RowCol) : base(Parent, WindowDim, Parent.ContentOdom) { this.StartRowCol = RowCol; }