Exemplo n.º 1
0
        public void Refresh(int screenCheckInterval)
        {
            Log.Verbose("Refresh::BEGIN");
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            //This line keeps checking to see when we've received a valid screen of data from the mainframe.
            //It loops until the TNEmulator.Refresh() method indicates that waiting for the screen did not time out.
            //This helps prevent blank screens, etc.
            lock (_lock)
            {
                while (!emu.Refresh(false, screenCheckInterval))
                {
                }
            }
            _Fields  = null;
            _Strings = null;
            Log.Verbose(string.Format("Refresh::END {0:mm\\:ss\\.fff}", sw.Elapsed));
            Redraw();
            CursorPositionSet?.Invoke(this, new EventArgs());
        }
Exemplo n.º 2
0
 private void Emulator_CursorPositionSet(byte Row, byte Column)
 {
     CursorX = Column;
     CursorY = Row;
     CursorPositionSet?.Invoke(this, new EventArgs());
 }
Exemplo n.º 3
0
        // public TextPointer Caret { get; set; }
        public void Redraw()
        {
            if (emulator == null)
            {
                return;
            }
            GenericTools.RunUI(() =>
            {
                try
                {
                    bool foundHighlight = false;
                    bool HighlightEdit  = false;
                    if (rtb.Document == null)
                    {
                        return;
                    }
                    rtb.Document.Blocks.Clear();
                    //var noSpaceStyle = new System.Windows.Style(typeof(Paragraph));
                    //noSpaceStyle.Setters.Add(new System.Windows.Setter(Paragraph.MarginProperty, new System.Windows.Thickness(0)));
                    //rtb.Resources.Add(typeof(Paragraph), noSpaceStyle);

                    for (var y = 1; y <= 25; y++)
                    {
                        var p         = new Paragraph();
                        p.LineHeight  = 1;
                        p.Margin      = new System.Windows.Thickness(0);
                        p.FontStretch = System.Windows.FontStretches.UltraExpanded;
                        p.FontSize    = 16;
                        var text      = "";
                        var fields    = new List <IBM5250.Emulator.EmulatorScreen.Field>();
                        fields.AddRange(emulator.Screen.Strings.Where(l => l.Location.Row == y && l.Allocated));
                        fields.AddRange(emulator.Screen.Fields.Where(l => l.Location.Row == y && l.Allocated));
                        fields = fields.OrderBy(x => x.Location.Column).ToList();
                        foreach (var field in fields)
                        {
                            if (field.Location.Column > (text.Length + 1))
                            {
                                var subtext = string.Format("{0," + (field.Location.Column - text.Length) + "}", "");
                                var subr    = new Run(subtext);
                                // subr.FontStretch = System.Windows.FontStretch.FromOpenTypeStretch(9);
                                subr.FontFamily = new System.Windows.Media.FontFamily("Consolas");
                                p.Inlines.Add(subr);
                                text += subtext;
                            }
                            if (field.Text == null)
                            {
                                field.Text = "";
                            }
                            var newtext = field.Text.PadRight(field.Location.Length);
                            // var newtext = string.Format("{0," + field.Location.Length + "}", field.Text);
                            if (text.Length > field.Location.Column)
                            {
                                continue;
                            }
                            text        += newtext;
                            var r        = new Run(newtext);
                            r.FontFamily = new System.Windows.Media.FontFamily("Consolas");



                            Color clr = Color.FromName(field.Attribute.ForeColor);
                            if (field.Attribute.ForeColor == "Background")
                            {
                                clr = Color.Black;
                            }
                            if (field.Attribute.ForeColor == "Green")
                            {
                                clr = Color.LimeGreen;
                            }
                            if (field.Attribute.ForeColor == "Turquoise")
                            {
                                clr = Color.Cyan;
                            }
                            if (field.Attribute.ForeColor == "Pink")
                            {
                                clr = Color.Fuchsia;
                            }
                            if (field.Attribute.ForeColor == "Blue")
                            {
                                clr = Color.CornflowerBlue;
                            }
                            r.Foreground = new System.Windows.Media.SolidColorBrush(
                                System.Windows.Media.Color.FromRgb(clr.R, clr.G, clr.B));

                            Color bck = Color.FromName(field.Attribute.BackColor);
                            if (field.Attribute.BackColor == "Background")
                            {
                                bck = Color.Black;
                            }
                            if (field.Attribute.BackColor == "Green")
                            {
                                bck = Color.LimeGreen;
                            }
                            if (field.Attribute.BackColor == "Turquoise")
                            {
                                bck = Color.Cyan;
                            }
                            if (field.Attribute.BackColor == "Pink")
                            {
                                bck = Color.Fuchsia;
                            }
                            if (field.Attribute.BackColor == "Blue")
                            {
                                bck = Color.CornflowerBlue;
                            }

                            r.Background = new System.Windows.Media.SolidColorBrush(
                                System.Windows.Media.Color.FromRgb(bck.R, bck.G, bck.B));

                            p.Inlines.Add(r);
                            if (field.Location.Row == HighlightCursorY)
                            {
                                if (HighlightCursorX >= field.Location.Column && HighlightCursorX <= (field.Location.Column + field.Location.Length))
                                {
                                    if (!foundHighlight || (!HighlightEdit && field.IsInputField))
                                    {
                                        foundHighlight = true;
                                        HighlightEdit  = field.IsInputField;
                                        bck            = Color.Red;
                                        clr            = Color.Yellow;
                                        if (field.IsInputField)
                                        {
                                            bck = Color.Green;
                                            clr = Color.Yellow;
                                        }
                                        r.Background = new System.Windows.Media.SolidColorBrush(
                                            System.Windows.Media.Color.FromRgb(bck.R, bck.G, bck.B));
                                        r.Foreground = new System.Windows.Media.SolidColorBrush(
                                            System.Windows.Media.Color.FromRgb(clr.R, clr.G, clr.B));
                                    }

                                    //var brush = (System.Windows.Media.SolidColorBrush)new System.Windows.Media.BrushConverter().ConvertFrom("#ffaacc");
                                    //r.BorderBrush = brush;
                                    //r.BorderThickness = new System.Windows.Thickness(1, 1, 1, 3);
                                }
                            }
                            if (!IsConnected)
                            {
                                bck          = Color.Black;
                                clr          = Color.Gray;
                                r.Background = new System.Windows.Media.SolidColorBrush(
                                    System.Windows.Media.Color.FromRgb(bck.R, bck.G, bck.B));
                                r.Foreground = new System.Windows.Media.SolidColorBrush(
                                    System.Windows.Media.Color.FromRgb(clr.R, clr.G, clr.B));
                            }
                        }
                        //if (text.Length < 80)
                        //{
                        //    var endstr = string.Format("{0," + (80 - text.Length) + "}", "");
                        //    var r = new Run(endstr);
                        //    p.Inlines.Add(r);
                        //    text += endstr;
                        //}
                        try
                        {
                            rtb.Document.Blocks.Add(p);
                        }
                        catch (Exception)
                        {
                            return;
                        }
                    }
                    CursorPositionSet?.Invoke(this, new EventArgs());
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                    return;
                }
            });
        }
Exemplo n.º 4
0
 private void Emu_CursorLocationChanged(object sender, EventArgs e)
 {
     CursorX = emu.CursorX;
     CursorY = emu.CursorY;
     CursorPositionSet?.Invoke(this, new EventArgs());
 }
Exemplo n.º 5
0
        public void Redraw()
        {
            if (!IsConnected)
            {
                Log.Verbose("");
            }
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            Log.Verbose("Redraw::BEGIN");
            GenericTools.RunUI(() =>
            {
                try
                {
                    bool foundHighlight = false;
                    bool HighlightEdit  = false;
                    if (rtb.Document == null)
                    {
                        return;
                    }
                    rtb.Document.Blocks.Clear();
                    //var noSpaceStyle = new System.Windows.Style(typeof(Paragraph));
                    //noSpaceStyle.Setters.Add(new System.Windows.Setter(Paragraph.MarginProperty, new System.Windows.Thickness(0)));
                    //rtb.Resources.Add(typeof(Paragraph), noSpaceStyle);

                    for (var y = 1; y <= 25; y++)
                    {
                        var p         = new Paragraph();
                        p.LineHeight  = 1;
                        p.Margin      = new System.Windows.Thickness(0);
                        p.FontStretch = System.Windows.FontStretches.UltraExpanded;
                        p.FontSize    = 16;
                        var text      = "";
                        var fields    = new List <Open3270.TN3270.XMLScreenField>();
                        fields.AddRange(Strings.Where(l => l.Location.top == y));
                        fields.AddRange(Fields.Where(l => l.Location.top == y));
                        fields = fields.OrderBy(x => x.Location.left).ToList();
                        foreach (var field in fields)
                        {
                            if (field.Location.left > (text.Length + 1))
                            {
                                var subtext = string.Format("{0," + (field.Location.left - text.Length) + "}", "");
                                var subr    = new Run(subtext);
                                // subr.FontStretch = System.Windows.FontStretch.FromOpenTypeStretch(9);
                                subr.FontFamily = new System.Windows.Media.FontFamily("Consolas");
                                p.Inlines.Add(subr);
                                text += subtext;
                            }
                            if (string.IsNullOrEmpty(field.Text))
                            {
                                field.Text = "";
                            }
                            var newtext = field.Text.PadRight(field.Location.length);
                            // var newtext = string.Format("{0," + field.Location.Length + "}", field.Text);
                            if (text.Length > field.Location.left)
                            {
                                continue;
                            }
                            text        += newtext;
                            var r        = new Run(newtext);
                            r.FontFamily = new System.Windows.Media.FontFamily("Consolas");
                            if (string.IsNullOrEmpty(field.Attributes.Foreground))
                            {
                                field.Attributes.Foreground = "Green";
                            }
                            if (string.IsNullOrEmpty(field.Attributes.Background))
                            {
                                field.Attributes.Background = "Background";
                            }
                            // Color clr = Color.FromName(field.Attributes.Foreground);
                            Color clr = Color.LimeGreen;
                            if (field.Attributes.Foreground == "Background")
                            {
                                clr = Color.Black;
                            }
                            if (field.Attributes.Foreground == "Green")
                            {
                                clr = Color.LimeGreen;
                            }
                            if (field.Attributes.Foreground == "Turquoise")
                            {
                                clr = Color.Cyan;
                            }
                            if (field.Attributes.Foreground == "Pink")
                            {
                                clr = Color.Fuchsia;
                            }
                            if (field.Attributes.Foreground == "Blue")
                            {
                                clr = Color.CornflowerBlue;
                            }
                            r.Foreground = new System.Windows.Media.SolidColorBrush(
                                System.Windows.Media.Color.FromRgb(clr.R, clr.G, clr.B));

                            // Color bck = Color.FromName(field.Attributes.Background);
                            Color bck = Color.Black;
                            if (field.Attributes.Background == "Background")
                            {
                                bck = Color.Black;
                            }
                            if (field.Attributes.Background == "Green")
                            {
                                bck = Color.LimeGreen;
                            }
                            if (field.Attributes.Background == "Turquoise")
                            {
                                bck = Color.Cyan;
                            }
                            if (field.Attributes.Background == "Pink")
                            {
                                bck = Color.Fuchsia;
                            }
                            if (field.Attributes.Background == "Blue")
                            {
                                bck = Color.CornflowerBlue;
                            }

                            r.Background = new System.Windows.Media.SolidColorBrush(
                                System.Windows.Media.Color.FromRgb(bck.R, bck.G, bck.B));

                            p.Inlines.Add(r);
                            if (field.Location.top == HighlightCursorY)
                            {
                                if (HighlightCursorX >= field.Location.left && HighlightCursorX <= (field.Location.left + field.Location.length))
                                {
                                    if (!foundHighlight || (!HighlightEdit && !field.Attributes.Protected))
                                    {
                                        foundHighlight = true;
                                        HighlightEdit  = !field.Attributes.Protected;
                                        bck            = Color.Red;
                                        clr            = Color.Yellow;
                                        if (!field.Attributes.Protected)
                                        {
                                            bck = Color.Green;
                                            clr = Color.Yellow;
                                        }
                                        r.Background = new System.Windows.Media.SolidColorBrush(
                                            System.Windows.Media.Color.FromRgb(bck.R, bck.G, bck.B));
                                        r.Foreground = new System.Windows.Media.SolidColorBrush(
                                            System.Windows.Media.Color.FromRgb(clr.R, clr.G, clr.B));
                                    }
                                }
                            }
                            if (!IsConnected)
                            {
                                bck          = Color.Black;
                                clr          = Color.Gray;
                                r.Background = new System.Windows.Media.SolidColorBrush(
                                    System.Windows.Media.Color.FromRgb(bck.R, bck.G, bck.B));
                                r.Foreground = new System.Windows.Media.SolidColorBrush(
                                    System.Windows.Media.Color.FromRgb(clr.R, clr.G, clr.B));
                            }
                        }
                        rtb.Document.Blocks.Add(p);
                    }
                    CursorPositionSet?.Invoke(this, new EventArgs());
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                    return;
                }
                finally
                {
                    Log.Verbose(string.Format("Redraw::END {0:mm\\:ss\\.fff}", sw.Elapsed));
                }
            });
        }