Exemple #1
0
        // 得到XPath
        public string GetXPath()
        {
            ElementItem root = (ElementItem)this.m_document.docRoot;

            string strPath;

            ItemUtil.Item2Path(root, this, out strPath);
            return(strPath);
        }
Exemple #2
0
        // 解决上移下移
        // 当光标移到文字顶时,再向上移则移到上一个Item
        // 当光标移到文字底时,再向下移则移到下一个Item
        protected override void OnKeyDown(KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Up:
            {
                // 当光标移到文字顶时,再向上移则移到上一个Item

                // 得到Edit的插入符位置
                int x, y;
                API.GetEditCurrentCaretPos(this,
                                           out x,
                                           out y);

                // 如果位置为0
                if (y == 0)
                {
                    POINT point = new POINT();
                    point.x = 0;
                    point.y = 0;
                    bool bRet = API.GetCaretPos(ref point);          //得到插入符

                    // 得到当前的Item的上一个Item
                    Item frontItem = ItemUtil.GetNearItem(this.XmlEditor.m_selectedItem,
                                                          MoveMember.Front);

                    if (frontItem != null)
                    {
                        // 设为当前的Item
                        //this.m_selectedItem = frontItem;
                        this.XmlEditor.SetCurText(frontItem, null);
                        this.XmlEditor.SetActiveItem(frontItem);
                        if (this.XmlEditor.m_curText != null)
                        {
                            // 手工单击一下,确保移动到对应的位置
                            point.y = this.ClientSize.Height - 2;
                            API.SendMessage(this.Handle,
                                            API.WM_LBUTTONDOWN,
                                            new UIntPtr(API.MK_LBUTTON), //	UIntPtr wParam,
                                            API.MakeLParam(point.x, point.y));

                            API.SendMessage(this.Handle,
                                            API.WM_LBUTTONUP,
                                            new UIntPtr(API.MK_LBUTTON), //	UIntPtr wParam,
                                            API.MakeLParam(point.x, point.y));
                        }
                        e.Handled = true;
                        this.XmlEditor.Invalidate();
                    }
                }
            }
            break;

            case Keys.Down:
            {
                // 当光标移到文字底时,再向下移则移到下一个Item

                int x, y;
                API.GetEditCurrentCaretPos(this,
                                           out x,
                                           out y);

                // 得到当前edit的行号
                int nTemp = API.GetEditLines(this);


                // 不是根元素
                if (y >= nTemp - 1 && (!(this.XmlEditor.m_selectedItem is VirtualRootItem)))
                {
                    POINT point = new POINT();
                    point.x = 0;
                    point.y = 0;
                    bool bRet = API.GetCaretPos(ref point);

                    // 得到下一个Item
                    Item behindItem = ItemUtil.GetNearItem(this.XmlEditor.m_selectedItem,
                                                           MoveMember.Behind);

                    if (behindItem != null)
                    {
                        //this.m_selectedItem = behindItem;
                        this.XmlEditor.SetCurText(behindItem, null);
                        this.XmlEditor.SetActiveItem(behindItem);



                        if (this.XmlEditor.m_curText != null)
                        {
                            // 模拟单击一下
                            point.y = 1;
                            API.SendMessage(this.Handle,
                                            API.WM_LBUTTONDOWN,
                                            new UIntPtr(API.MK_LBUTTON), //	UIntPtr wParam,
                                            API.MakeLParam(point.x, point.y));

                            API.SendMessage(this.Handle,
                                            API.WM_LBUTTONUP,
                                            new UIntPtr(API.MK_LBUTTON), //	UIntPtr wParam,
                                            API.MakeLParam(point.x, point.y));
                        }
                        e.Handled = true;

                        this.XmlEditor.Invalidate();
                    }
                }
            }
            break;

            case Keys.Left:
                break;

            case Keys.Right:
                break;

            default:
                break;
            }
        }