Example #1
0
        /// <summary>
        /// paint the text and fields of the screen content block onto the item canvas.
        /// </summary>
        /// <param name="ScreenContent"></param>
        /// <param name="ItemCanvas"></param>
        /// <param name="Window"></param>
        public static void PaintScreenContent(this ScreenContent ScreenContent,
                                              ItemCanvas ItemCanvas)
        {
            // use ContentNum to match ScreenContent with the ItemCanvas.
            ItemCanvas.ContentNum = ScreenContent.ContentNum;

            // apply the clear unit command to the itemcanvas.
            if (ScreenContent.DoClearUnit == true)
            {
                ItemCanvas.EraseScreen();
                ScreenContent.DoClearUnit = false;
            }

            else
            {
                // add ContentText items to the ContentDict of the SCB.
                ScreenContent.AddAllContentText();
            }

            // Remove all items on the ItemCanvas that are not in the SCB.
            // todo: need to clear the caret position if field removed from the screen
            //       contains the caret.
            var visualItems = ItemCanvas.VisualItems;

            foreach (var itemCursor in visualItems.ItemList())
            {
                var             vi          = itemCursor.GetVisualItem();
                var             rowCol      = vi.ItemRowCol;
                ContentItemBase contentItem = null;
                var             rc          = ScreenContent.FieldDict.TryGetValue(rowCol, out contentItem);
                if (rc == false)
                {
                    visualItems.RemoveItem(itemCursor, ItemCanvas);
                }
            }

            // loop for each item within the content array.
            foreach (var contentItem in ScreenContent.ContentItems())
            {
                if (contentItem is ContentText)
                {
                    var contentText = contentItem as ContentText;
                    var visualItem  = ItemCanvas.VisualItemFactory(
                        contentText.GetShowText(ScreenContent),
                        contentText.RowCol, contentText.GetAttrByte(ScreenContent),
                        contentText.GetTailAttrByte(ScreenContent));

                    var iMore = visualItem as IVisualItemMore;
                    var node  = iMore.InsertIntoVisualItemsList(ItemCanvas.VisualItems);
                    iMore.AddToCanvas(ItemCanvas);
                    iMore.SetupUnderline();
                }

                else if (contentItem is ContentField)
                {
                    var contentField = contentItem as ContentField;
                    var visualItem   =
                        ItemCanvas.VisualItemFactory(ScreenContent, contentField);

                    if (visualItem != null)
                    {
                        var iMore = visualItem as IVisualItemMore;
                        var node  = iMore.InsertIntoVisualItemsList(ItemCanvas.VisualItems);
                        iMore.AddToCanvas(ItemCanvas);
                        iMore.SetupUnderline();
                        iMore.SetupFieldItem(
                            ScreenContent, contentField,
                            ItemCanvas.CanvasDefn.CharBoxDim, ItemCanvas.CanvasDefn.KernDim);
                    }
                }
            }

            // position the caret.
            ItemCanvas.PositionCaret(ScreenContent.CaretRowCol);
            ItemCanvas.SetFocus();
        }
        /// <summary>
        /// import the ContentItems of the current ScreenContent. Use the MasterThread
        /// property to send a message to the MasterThread asking for a copy of the
        /// current screenContent. That sent message waits for a response and receives
        /// the screenContent as the reply. With the screenContent, then list the
        /// ScreenContent items and import into ScreenDefn.
        ///
        /// Necessary for this to work, the telnetClient which is the parent of the
        /// ScreenDefnListControl must bind to the MasterThread property.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void butImport_Click(object sender, RoutedEventArgs e)
        {
            // send a message to the master thread asking for a copy of the current
            // screenContent.
            ScreenContent content = null;
            {
                var msg = new ExchangeMessage(ThreadMessageCode.GetScreenContent);
                this.MasterThread.PostInputMessage(msg);
                msg.WaitReplyEvent();
                content = msg.ReplyMessage as ScreenContent;
            }

            // create screen section. type body.
            var section = new ScreenSectionModel()
            {
                ScreenLoc   = new OneScreenLoc(1, 1),
                ItemName    = "Body",
                ItemType    = ShowItemType.Section,
                PurposeCode = ScreenPurposeCode.Body
            };

            this.Model.AddItem(section);

            int fieldNum = 0;
            int litNum   = 0;

            foreach (var citem in content.ContentItems( ))
            {
                if (citem is ContentField)
                {
                    var fld = citem as ContentField;

                    {
                        fieldNum += 1;
                        var xx   = fld.IsBypass;
                        var item = new ScreenFieldModel()
                        {
                            ScreenLoc = new OneScreenLoc(fld.RowCol.ToOneBased()),
                            ItemName  = "Field" + fieldNum,
                            Length    = fld.LL_Length,
                            ItemType  = ShowItemType.Field,
                            Usage     = fld.Usage,
                            DsplyAttr = fld.AttrByte.ToDsplyAttr()
                        };
                        section.AddItem(item);
                    }
                }
                else if (citem is ContentText)
                {
                    var contentText = citem as ContentText;
                    {
                        litNum += 1;
                        var item = new ScreenLiteralModel()
                        {
                            ScreenLoc  = new OneScreenLoc(contentText.RowCol.ToOneBased()),
                            ItemName   = "Lit" + litNum,
                            ListValues = contentText.GetShowText(content).ToListString().ToObservableCollection( ),
                            Length     = contentText.GetShowText(content).Length,
                            ItemType   = ShowItemType.Literal,
                            DsplyAttr  = contentText.GetAttrByte(content).ToDsplyAttr()
                        };

#if skip
                        // adjust screenLoc to account for neutral dsply attr.
                        if (item.DsplyAttr.IsEqual(DsplyAttr.NU))
                        {
                            item.ScreenLoc = item.ScreenLoc.Advance(1, new AutoCoder.Telnet.Common.ScreenDm.ScreenDim(24, 80)) as OneScreenLoc;
                        }
#endif

                        section.AddItem(item);
                    }
                }
            }
        }