Example #1
0
        public static ItemCanvas CreateItemCanvas(this WindowScreenContent ScreenContent,
                                                  ItemCanvas ParentItemCanvas, MasterThread MasterThread,
                                                  PaintThread PaintThread)
        {
            // create the canvas to drawn upon.
            var rv = ScreenContent.CreateWindowedItemCanvas(
                ParentItemCanvas, ParentItemCanvas.CanvasDefn.FontDefn.PointSize,
                MasterThread, PaintThread, ScreenContent.ContentNum);
            var border     = rv.Item1;
            var itemCanvas = rv.Item2;

            itemCanvas.ContentStart = ScreenContent.StartCharPoint;

            // add the canvas control ( actually the border control that contains the
            // canvas ) to the parent canvas.
            var canvasPos = ParentItemCanvas.AddItemToCanvas(
                ScreenContent.StartRowCol, itemCanvas.BorderControl);

            ScreenContent.WindowPos = canvasPos;

            ParentItemCanvas.RemoveCaret();
            itemCanvas.SetFocus();
            itemCanvas.HookBorderDrag();

            return(itemCanvas);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="PointSize"></param>
        /// <param name="MasterThread"></param>
        /// <returns></returns>
        public Tuple <Border, ItemCanvas> CreateWindowedItemCanvas(
            ItemCanvas ParentItemCanvas,
            double PointSize, MasterThread MasterThread, PaintThread PaintThread,
            int ContentNum)
        {
            Border border = null;

            System.Windows.Controls.Canvas canvas = null;

            border = new Border();
            border.BorderThickness = new Thickness(3);
            border.Margin          = new Thickness(5);
            border.BorderBrush     = Brushes.Aquamarine;
            border.CornerRadius    = new CornerRadius(3);

            canvas       = new System.Windows.Controls.Canvas();
            border.Child = canvas;

            var itemCanvas = new ItemCanvas(
                canvas, this.ScreenDim, PointSize, MasterThread, PaintThread,
                ContentNum);

//      this.ItemCanvas = itemCanvas;

            // add this itemCanvas to the Children of the parent ItemCanvas.
            ParentItemCanvas.AddChild(itemCanvas);

            // store reference to the Border in the ItemCanvas.  Used in the PaintThread
            // when adding the border and its contained canvas to the Telnet canvas.
            itemCanvas.BorderControl = border;

            var boxDim = itemCanvas.CanvasDefn.CharBoxDim;
            var dim    = this.ScreenDim.ToCanvasDim(boxDim);

            canvas.Width      = dim.Width;
            canvas.Height     = dim.Height;
            canvas.Background = Brushes.Black;

            canvas.Focusable = true;
            canvas.IsEnabled = true;
            canvas.Focus();

            return(new Tuple <Border, ItemCanvas>(border, itemCanvas));
        }
Example #3
0
        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);
        }
Example #4
0
        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));
        }
Example #5
0
        /// <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));
        }
Example #6
0
        public void EntryPoint()
        {
            this.ThreadEndedEvent.Reset();
            var master = BaseMaster_InitialSetup();

            try
            {
                // loop receiving from the server until:
                //   - the foreground thread wants to shutdown the connection. It has set
                //     the ShutdownFlag event.
                while ((ShutdownFlag.State == false) &&
                       (this.ConnectionFailedEvent.State == false))
                {
                    var message = InputQueue.WaitAndDequeue(
                        this.ShutdownFlag.EventObject, this.ConnectionFailedEvent.EventObject);
                    if (message != null)
                    {
                        if (message is WorkstationCommandListMessage)
                        {
                            var cmdList = (message as WorkstationCommandListMessage).WorkstationCommandList;

                            var rv = this.BaseMaster.Apply(
                                cmdList, this.ToThread, this.PaintThread, this.LogList);
                            bool wtdApplied = rv.Item1;
                            this.BaseMaster = rv.Item2;

                            // signal the paint thread to paint the canvas with the screen
                            // content block.
                            if (wtdApplied == true)
                            {
                                this.BaseMaster.PostAidKey = this.PostAidKey;
                                this.PostAidKey            = null;
                                var masterCopy   = this.BaseMaster.Copy();
                                var content      = masterCopy.GetWorkingContentBlock();
                                var paintMessage = new PaintCanvasMessage(content);
                                this.PaintThread.PostInputMessage(paintMessage);
                            }

                            // send another copy of the screenContent to the match thread.
                            // Match thread will match the screen to the screen definitions.
                            // Looking for screen id, hover code, help text, etc.
                            if (wtdApplied == true)
                            {
                                var masterCopy = this.BaseMaster.Copy();
                                var content    = masterCopy.GetWorkingContentBlock();
                                this.MatchThread.PostInputMessage(
                                    ThreadMessageCode.MatchScreenContentToScreenDefn, content);
                            }
                        }

                        else if (message is KeyboardInputMessage)
                        {
                            var kbInput = message as KeyboardInputMessage;
                            if (kbInput.Text != null)
                            {
                                master = this.BaseMaster.GetWorkingContentBlock();
                                master.ApplyInput(kbInput);
                            }
                        }

                        // message sent from UI thread when the caret is moved. See the
                        // ItemCanvas class.
                        else if (message is CaretMoveMessage)
                        {
                            var caretMove = message as CaretMoveMessage;
                            master = this.BaseMaster.GetWorkingContentBlock();
                            master.ApplyCaretMove(caretMove);
                        }

                        // enter key has been pressed. UI thread sent the message to this
                        // Master thread. Master thread relays the message to the
                        // ToThread along with a copy of the master ScreenContent. ToThread
                        // creates and sends the response data stream based on the master
                        // screen content.
                        else if (message is AidKeyResponseMessage)
                        {
                            var msg = message as AidKeyResponseMessage;
                            this.PostAidKey   = msg.AidKey;
                            msg.ScreenContent = this.BaseMaster.Copy();
                            ToThread.PostInputMessage(msg);
                        }

                        else if (message is GeneralThreadMessage)
                        {
                            var generalMessage = message as GeneralThreadMessage;
                            switch (generalMessage.MessageCode)
                            {
                            case ThreadMessageCode.ClearLog:
                            {
                                this.LogList.Clear();
                                break;
                            }

                            // report visual items. Add screenContent to the message and
                            // send it to PaintThread.
                            case ThreadMessageCode.ReportVisualItems:
                            {
                                generalMessage.ScreenContent = this.BaseMaster.Copy();
                                PaintThread.PostInputMessage(generalMessage);
                                break;
                            }
                            }
                        }

                        else if (message is ExchangeMessage)
                        {
                            var exchangeMessage = message as ExchangeMessage;
                            if (exchangeMessage.MessageCode == ThreadMessageCode.GetScreenContent)
                            {
                                master = this.BaseMaster.GetWorkingContentBlock();
                                var masterCopy = master.Copy();
                                exchangeMessage.PostReplyMessage(masterCopy);
                            }
                        }
                    }
                }
            }
            finally
            {
                // in case anyone waiting for this thread to end. Signal the ended event.
                ThreadEndedEvent.Set();
            }
        }
Example #7
0
 public ItemCanvas(
     System.Windows.Controls.Canvas canvas, double charWidth, double charHeight,
     ScreenDim ScreenDim, double FontPointSize, PaintThread PaintThread)
     : this(canvas, ScreenDim, FontPointSize, null, PaintThread, 0)
 {
 }