示例#1
0
文件: ItemToolTip.cs 项目: mo5h/omeo
        internal void HandleWMNotify(ref Message m)
        {
            uint  pos = Win32Declarations.GetMessagePos();
            Point pt  = new Point(Win32Declarations.LOWORD(pos), Win32Declarations.HIWORD(pos));

            pt = _ownerControl.PointToClient(pt);

            NMHDR nmhdr = (NMHDR)m.GetLParam(typeof(NMHDR));

            if (nmhdr.code == Win32Declarations.TTN_NEEDTEXTW)
            {
                NMTTDISPINFOW dispInfo = (NMTTDISPINFOW)m.GetLParam(typeof(NMTTDISPINFOW));
                _lastToolTipNode   = _ownerControl.GetNodeAt(pt);
                _lastToolTipColumn = _ownerControl.GetColumnAt(pt);
                string tooltip = null;
                if (_lastToolTipColumn != null && _lastToolTipNode != null)
                {
                    Rectangle rc = _ownerControl.GetItemBounds(_lastToolTipNode, _lastToolTipColumn);
                    _lastNeedPlace    = true;
                    tooltip           = _lastToolTipColumn.GetToolTip(_lastToolTipNode, rc, ref _lastNeedPlace);
                    _lastItemShowRect = rc;
                }
                if (tooltip == null || tooltip.Length == 0)
                {
                    dispInfo.szText   = "";
                    dispInfo.lpszText = IntPtr.Zero;
                }
                else
                {
                    dispInfo.lpszText = _toolTipPool.PinString(tooltip);
                }
                Marshal.StructureToPtr(dispInfo, m.LParam, false);
            }
            else if (nmhdr.code == Win32Declarations.TTN_SHOW && _lastNeedPlace)
            {
                Rectangle scItemShowRect = _ownerControl.RectangleToScreen(_lastItemShowRect);
                RECT      rc             = Win32Declarations.RectangleToRECT(scItemShowRect);
                Win32Declarations.SendMessage(Handle, (LVM)Win32Declarations.TTM_ADJUSTRECT,
                                              1, ref rc);

                Win32Declarations.SetWindowPos(Handle, IntPtr.Zero, rc.left, rc.top, 0, 0,
                                               Win32Declarations.SWP_NOSIZE | Win32Declarations.SWP_NOZORDER | Win32Declarations.SWP_NOACTIVATE);
                m.Result = (IntPtr)1;
            }
        }
示例#2
0
        public void BeginEdit(JetListView jetListView, JetListViewColumn col, JetListViewNode node)
        {
            _host       = jetListView;
            _editColumn = col;
            _editNode   = node;

            if (!jetListView.Controls.Contains(_inPlaceEditBox))
            {
                jetListView.Controls.Add(_inPlaceEditBox);
            }

            Rectangle rc = jetListView.GetItemBounds(node, col);

            if (col.SizeToContent)
            {
                rc.Width = jetListView.InternalClientRect().Width - rc.Left;
            }
            JetItemEditEventArgs args = new JetItemEditEventArgs(col.GetItemText(node.Data, rc.Width),
                                                                 node.Data, col);

            OnBeforeItemEdit(args);
            if (args.CancelEdit)
            {
                return;
            }

            jetListView.ScrollInView(node);
            jetListView.SetEditedNode(node);

            _inPlaceEditRect       = new Rectangle(rc.Left - 2, rc.Top - 1, rc.Width + 4, rc.Height + 2);
            _inPlaceEditBox.Bounds = _inPlaceEditRect;
            _inPlaceEditBox.Text   = args.Text;
            _startEditText         = args.Text;
            AutosizeInPlaceEdit();
            _inPlaceEditBox.Visible = true;
            _inPlaceEditBox.Focus();
        }