Example #1
0
 protected override Rectangle GetFocusedItemRect()
 {
     if (HasFocus())
     {
         int code = ShellBrowser.ViewMode == FVM.DETAILS ? LVIR.LABEL : LVIR.BOUNDS;
         return(GetItemRect(ShellBrowser.GetFocusedIndex(), code).ToRectangle());
     }
     return(new Rectangle(0, 0, 0, 0));
 }
Example #2
0
        protected override bool HandleCursorLoop(Keys key)
        {
            int focusedIdx = ShellBrowser.GetFocusedIndex();
            int itemCount  = ShellBrowser.GetItemCount();
            int selectMe   = -1;
            int viewMode   = ShellBrowser.ViewMode;

            if (viewMode == FVM.TILE && QTUtility.IsXP)
            {
                viewMode = FVM.ICON;
            }
            switch (viewMode)
            {
            case FVM.CONTENT:
            case FVM.DETAILS:
            case FVM.TILE:
                if (key == Keys.Up && focusedIdx == 0)
                {
                    selectMe = itemCount - 1;
                }
                else if (key == Keys.Down && focusedIdx == itemCount - 1)
                {
                    selectMe = 0;
                }
                break;

            case FVM.ICON:
            case FVM.SMALLICON:
            case FVM.THUMBNAIL:
            case FVM.LIST:
                Keys   KeyNextItem, KeyPrevItem, KeyNextPage, KeyPrevPage;
                IntPtr MsgNextPage, MsgPrevPage;
                if (viewMode == FVM.LIST)
                {
                    KeyNextItem = Keys.Down;
                    KeyPrevItem = Keys.Up;
                    KeyNextPage = Keys.Right;
                    KeyPrevPage = Keys.Left;
                    MsgNextPage = (IntPtr)LVNI.TORIGHT;
                    MsgPrevPage = (IntPtr)LVNI.TOLEFT;
                }
                else
                {
                    KeyNextItem = Keys.Right;
                    KeyPrevItem = Keys.Left;
                    KeyNextPage = Keys.Down;
                    KeyPrevPage = Keys.Up;
                    MsgNextPage = (IntPtr)LVNI.BELOW;
                    MsgPrevPage = (IntPtr)LVNI.ABOVE;
                }

                int nextPageIdx = (int)PInvoke.SendMessage(Handle, LVM.GETNEXTITEM, (IntPtr)focusedIdx, MsgNextPage);
                if (nextPageIdx == -1 || nextPageIdx == focusedIdx)
                {
                    nextPageIdx = (int)PInvoke.SendMessage(Handle, LVM.GETNEXTITEM, (IntPtr)focusedIdx, MsgPrevPage);
                }
                else if (QTUtility.IsXP)
                {
                    int testIdx = (int)PInvoke.SendMessage(Handle, LVM.GETNEXTITEM, (IntPtr)nextPageIdx, MsgPrevPage);
                    if (testIdx != focusedIdx)
                    {
                        nextPageIdx = (int)PInvoke.SendMessage(Handle, LVM.GETNEXTITEM, (IntPtr)focusedIdx, MsgPrevPage);
                    }
                }
                if (nextPageIdx == -1 || nextPageIdx == focusedIdx)
                {
                    if (key == KeyNextItem)
                    {
                        if (focusedIdx == itemCount - 1)
                        {
                            selectMe = 0;
                        }
                        else
                        {
                            RECT thisRect = GetItemRect(focusedIdx);
                            RECT nextRect = GetItemRect(focusedIdx + 1);
                            if (viewMode == FVM.LIST)
                            {
                                if (nextRect.top < thisRect.top)
                                {
                                    selectMe = 0;
                                }
                            }
                            else if (nextRect.left < thisRect.left)
                            {
                                selectMe = 0;
                            }
                        }
                    }
                    else if (key == KeyPrevItem && focusedIdx == 0)
                    {
                        selectMe = itemCount - 1;
                    }
                    else if (key == KeyNextPage || key == KeyPrevPage)
                    {
                        if (QTUtility.IsXP)
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    int pageCount = Math.Abs(focusedIdx - nextPageIdx);
                    int page      = focusedIdx % pageCount;
                    if (key == KeyNextItem && (page == pageCount - 1 || focusedIdx == itemCount - 1))
                    {
                        selectMe = focusedIdx - page;
                    }
                    else if (key == KeyPrevItem && page == 0)
                    {
                        selectMe = Math.Min(focusedIdx + pageCount - 1, itemCount - 1);
                    }
                    else if (key == KeyNextPage && focusedIdx + pageCount >= itemCount)
                    {
                        selectMe = page;
                    }
                    else if (key == KeyPrevPage && focusedIdx < pageCount)
                    {
                        int x = itemCount - focusedIdx - 1;
                        selectMe = x - x % pageCount + focusedIdx;
                    }
                }
                break;
            }

            if (selectMe >= 0)
            {
                SetRedraw(false);
                ShellBrowser.SelectItem(selectMe);
                PInvoke.SendMessage(Handle, LVM.REDRAWITEMS, (IntPtr)focusedIdx, (IntPtr)focusedIdx);
                SetRedraw(true);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        protected override Point GetSubDirTipPoint(bool fByKey)
        {
            int   iItem = fByKey ? ShellBrowser.GetFocusedIndex() : GetHotItem();
            int   x, y;
            Point ret;
            RECT  rect;

            switch (ShellBrowser.ViewMode)
            {
            case FVM.DETAILS:
                rect = GetItemRect(iItem, LVIR.LABEL);
                x    = rect.right;
                y    = rect.top;
                y   += (rect.bottom - y) / 2;
                ret  = new Point(x - 19, y - 7);
                break;

            case FVM.SMALLICON:
                rect = GetItemRect(iItem);
                x    = rect.right;
                y    = rect.top;
                x   -= (rect.bottom - y) / 2;
                y   += (rect.bottom - y) / 2;
                ret  = new Point(x - 9, y - 7);
                break;

            case FVM.CONTENT:
            case FVM.TILE:
                rect = GetItemRect(iItem, LVIR.ICON);
                y    = rect.bottom;
                x    = rect.right;
                ret  = new Point(x - 16, y - 16);
                break;

            case FVM.THUMBSTRIP:
            case FVM.THUMBNAIL:
                rect = GetItemRect(iItem, LVIR.ICON);
                if (QTUtility.IsXP)
                {
                    rect.right -= 13;
                }
                y   = rect.bottom;
                x   = rect.right;
                ret = new Point(x - 16, y - 16);
                break;

            case FVM.ICON:
                rect = GetItemRect(iItem, LVIR.ICON);
                if (QTUtility.IsXP)
                {
                    int  num3     = (int)PInvoke.SendMessage(Handle, LVM.GETITEMSPACING, IntPtr.Zero, IntPtr.Zero);
                    Size iconSize = SystemInformation.IconSize;
                    rect.right  = ((rect.left + (((num3 & 0xffff) - iconSize.Width) / 2)) + iconSize.Width) + 8;
                    rect.bottom = (rect.top + iconSize.Height) + 6;
                }
                y   = rect.bottom;
                x   = rect.right;
                ret = new Point(x - 16, y - 16);
                break;

            case FVM.LIST:
                if (QTUtility.IsXP)
                {
                    rect = GetItemRect(iItem, LVIR.ICON);
                    LVITEM structure = new LVITEM();
                    structure.pszText    = Marshal.AllocHGlobal(520);
                    structure.cchTextMax = 260;
                    structure.iItem      = iItem;
                    structure.mask       = 1;
                    IntPtr zero = Marshal.AllocHGlobal(Marshal.SizeOf(structure));
                    Marshal.StructureToPtr(structure, zero, false);
                    PInvoke.SendMessage(Handle, LVM.GETITEM, IntPtr.Zero, zero);
                    int num4 = (int)PInvoke.SendMessage(Handle, LVM.GETSTRINGWIDTH, IntPtr.Zero, structure.pszText);
                    num4 += 20;
                    Marshal.FreeHGlobal(structure.pszText);
                    Marshal.FreeHGlobal(zero);
                    rect.right  += num4;
                    rect.top    += 2;
                    rect.bottom += 2;
                }
                else
                {
                    rect = GetItemRect(iItem, LVIR.LABEL);
                }
                y   = rect.bottom;
                x   = rect.right;
                ret = new Point(x - 16, y - 16);
                break;

            default:
                rect = GetItemRect(iItem);
                y    = rect.bottom;
                x    = rect.right;
                ret  = new Point(x - 16, y - 16);
                break;
            }
            PInvoke.ClientToScreen(Handle, ref ret);
            return(ret);
        }
Example #4
0
        protected override bool ListViewController_MessageCaptured(ref Message msg)
        {
            if (msg.Msg == WM_AFTERPAINT)
            {
                RefreshCache();
            }
            else if (msg.Msg == WM_ISITEMSVIEW)
            {
                msg.Result = (IntPtr)1;
                return(true);
            }

            if (base.ListViewController_MessageCaptured(ref msg))
            {
                return(true);
            }

            switch (msg.Msg)
            {
            case LVM.SCROLL: {
                int amount = msg.WParam.ToInt32();
                SetRedraw(false);
                AutomationManager.DoQuery(factory => {
                        AutomationElement elem = factory.FromHandle(Handle);
                        amount  /= SystemInformation.MouseWheelScrollDelta;
                        bool dec = amount < 0;
                        if (dec)
                        {
                            amount = -amount;
                        }
                        int lines = SystemInformation.MouseWheelScrollLines;
                        if (lines < 0)
                        {
                            elem.ScrollHorizontal(dec
                                    ? ScrollAmount.LargeDecrement
                                    : ScrollAmount.LargeIncrement, amount);
                        }
                        else
                        {
                            elem.ScrollHorizontal(dec
                                    ? ScrollAmount.SmallDecrement
                                    : ScrollAmount.SmallIncrement, amount * lines);
                        }
                        return(0);
                    });
                SetRedraw(true);
                return(true);
            }

            case WM.MOUSEACTIVATE: {
                int  res = (int)msg.Result;
                bool ret = OnMouseActivate(ref res);
                msg.Result = (IntPtr)res;
                return(ret);
            }

            case WM.LBUTTONDOWN: {
                // The ItemsView's window class doesn't have the CS_DBLCLKS
                // class style, which means we won't be receiving the
                // WM.LBUTTONDBLCLK message.  We'll just have to make do
                // without...
                Int64 now = DateTime.Now.Ticks;
                Point pt  = QTUtility2.PointFromLPARAM(msg.LParam);
                if ((now - lastLButtonTime) / 10000 <= SystemInformation.DoubleClickTime)
                {
                    Size size = SystemInformation.DoubleClickSize;
                    if (Math.Abs(pt.X - lastLButtonPoint.X) <= size.Width)
                    {
                        if (Math.Abs(pt.Y - lastLButtonPoint.Y) <= size.Height)
                        {
                            lastLButtonTime = 0;
                            return(OnDoubleClick(pt));
                        }
                    }
                }
                lastLButtonPoint = pt;
                lastLButtonTime  = now;
                return(false);
            }

            case WM.MOUSEMOVE: {
                Point pt = QTUtility2.PointFromLPARAM(msg.LParam);
                if (pt != lastMouseMovePoint)
                {
                    lastMouseMovePoint = pt;
                    if (focusedElement != null)
                    {
                        if (hotElement == null && focusedElement.FullRect.Contains(pt))
                        {
                            PInvoke.PostMessage(Handle, WM_AFTERPAINT, IntPtr.Zero, IntPtr.Zero);
                        }
                        else if (hotElement != null && hotElement.Index == focusedElement.Index && !focusedElement.FullRect.Contains(pt))
                        {
                            PInvoke.PostMessage(Handle, WM_AFTERPAINT, IntPtr.Zero, IntPtr.Zero);
                        }
                    }
                }
                break;
            }

            case WM.MOUSELEAVE:
                if (focusedElement != null)
                {
                    if (hotElement != null && hotElement.Index == focusedElement.Index)
                    {
                        PInvoke.PostMessage(Handle, WM_AFTERPAINT, IntPtr.Zero, IntPtr.Zero);
                    }
                }
                break;

            case WM.KEYDOWN:
                return(OnKeyDown((Keys)msg.WParam));

            case WM.LBUTTONUP:
            case WM.RBUTTONUP:
            case WM.MBUTTONUP:
                RefreshCache();
                break;

            case WM.NOTIFY: {
                NMHDR nmhdr = (NMHDR)Marshal.PtrToStructure(msg.LParam, typeof(NMHDR));
                if (nmhdr.code == -530 /* TTN_NEEDTEXT */)
                {
                    NMTTDISPINFO dispinfo = (NMTTDISPINFO)Marshal.PtrToStructure(msg.LParam, typeof(NMTTDISPINFO));
                    if ((dispinfo.uFlags & 0x20 /* TTF_TRACK */) != 0)
                    {
                        return(OnGetInfoTip(ShellBrowser.GetFocusedIndex(), true));
                    }
                    else
                    {
                        int i = GetHotItem();
                        if (i != -1 && IsTrackingItemName())
                        {
                            return(OnGetInfoTip(i, false));
                        }
                    }
                }
                break;
            }
            }
            return(false);
        }
Example #5
0
        // 使用箭头键时候环绕选择文件夹
        protected override bool HandleCursorLoop(Keys key)
        {
            int focusedIdx = ShellBrowser.GetFocusedIndex();
            int itemCount  = ShellBrowser.GetItemCount();
            int selectMe   = -1;
            FVM viewMode   = ShellBrowser.ViewMode;

            switch (viewMode)
            {
            case FVM.CONTENT:
            case FVM.DETAILS:
                if (key == Keys.Up && focusedIdx == 0)
                {
                    selectMe = itemCount - 1;
                }
                else if (key == Keys.Down && focusedIdx == itemCount - 1)
                {
                    selectMe = 0;
                }
                break;

            case FVM.ICON:
            case FVM.SMALLICON:
            case FVM.THUMBNAIL:
            case FVM.TILE:
            case FVM.LIST:
                Keys KeyNextItem, KeyPrevItem, KeyNextPage, KeyPrevPage;
                if (viewMode == FVM.LIST)
                {
                    KeyNextItem = Keys.Down;
                    KeyPrevItem = Keys.Up;
                    KeyNextPage = Keys.Right;
                    KeyPrevPage = Keys.Left;
                }
                else
                {
                    KeyNextItem = Keys.Right;
                    KeyPrevItem = Keys.Left;
                    KeyNextPage = Keys.Down;
                    KeyPrevPage = Keys.Up;
                }
                int pageCount = AutomationManager.DoQuery(factory => {
                    AutomationElement elem = factory.FromHandle(Handle);
                    if (elem == null)
                    {
                        return(-1);
                    }
                    return(viewMode == FVM.LIST ? elem.GetRowCount() : elem.GetColumnCount());
                });
                if (pageCount == -1)
                {
                    return(false);
                }
                int page = focusedIdx % pageCount;
                if (key == KeyNextItem && (page == pageCount - 1 || focusedIdx == itemCount - 1))
                {
                    selectMe = focusedIdx - page;
                }
                else if (key == KeyPrevItem && page == 0)
                {
                    selectMe = Math.Min(focusedIdx + pageCount - 1, itemCount - 1);
                }
                else if (key == KeyNextPage && focusedIdx + pageCount >= itemCount)
                {
                    selectMe = page;
                }
                else if (key == KeyPrevPage && focusedIdx < pageCount)
                {
                    int x = itemCount - focusedIdx - 1;
                    selectMe = x - x % pageCount + focusedIdx;
                }
                break;
            }
            if (selectMe >= 0)
            {
                ShellBrowser.SelectItem(selectMe);
                return(true);
            }
            else
            {
                return(false);
            }
        }