Example #1
0
        private void RecaptureHandles(IntPtr hwndShellView)
        {
            if (CurrentListView != null)
            {
                CurrentListView.Dispose();
            }

            hwndEnumResult = IntPtr.Zero;
            PInvoke.EnumChildWindows(hwndShellView, CallbackEnumChildProc_ListView, IntPtr.Zero);
            if (hwndEnumResult == IntPtr.Zero)
            {
                CurrentListView = new AbstractListView();
            }
            else if (fIsSysListView)
            {
                CurrentListView = new ExtendedSysListView32(ShellBrowser, hwndShellView, hwndEnumResult, hwndSubDirTipMessageReflect);
            }
            else
            {
                if (AutoMan == null)
                {
                    AutoMan = new AutomationManager();
                }
                CurrentListView = new ExtendedItemsView(ShellBrowser, hwndShellView, hwndEnumResult, hwndSubDirTipMessageReflect, AutoMan);
            }
            CurrentListView.ListViewDestroyed += ListView_Destroyed;
            ListViewChanged(this, null);
        }
Example #2
0
 public override bool HotItemIsSelected()
 {
     return(AutomationManager.DoQuery(factory => {
         AutomationElement elem = ListItemElementFromPoint(factory, Control.MousePosition);
         return elem == null ? false : elem.IsSelected();
     }));
 }
Example #3
0
 public override bool PointIsBackground(Point pt, bool screenCoords)
 {
     if (!screenCoords)
     {
         PInvoke.ClientToScreen(ListViewController.Handle, ref pt);
     }
     return(AutomationManager.DoQuery(factory => {
         AutomationElement elem = factory.FromPoint(pt);
         if (elem == null)
         {
             return false;
         }
         string className = elem.GetClassName();
         return className == "UIItemsView" || className == "UIGroupItem";
     }));
 }
Example #4
0
        private void RecaptureHandles(IntPtr hwndShellView)
        {
            bool   fIsSysListView = false;
            IntPtr hwndListView   = WindowUtils.FindChildWindow(hwndShellView, hwnd => {
                string name = PInvoke.GetClassName(hwnd);
                if (name == "SysListView32")
                {
                    fIsSysListView = true;
                    return(true);
                }
                else if (!QTUtility.IsXP && name == "DirectUIHWND")
                {
                    fIsSysListView = false;
                    return(true);
                }
                return(false);
            });

            if (CurrentListView != null)
            {
                if (CurrentListView.Handle == hwndListView)
                {
                    return;
                }
                PreviousListView = CurrentListView;
            }

            if (hwndListView == IntPtr.Zero)
            {
                CurrentListView = new AbstractListView();
            }
            else if (fIsSysListView)
            {
                CurrentListView = new ExtendedSysListView32(ShellBrowser, hwndShellView, hwndListView, hwndSubDirTipMessageReflect);
            }
            else
            {
                if (AutoMan == null)
                {
                    AutoMan = new AutomationManager();
                }
                CurrentListView = new ExtendedItemsView(ShellBrowser, hwndShellView, hwndListView, hwndSubDirTipMessageReflect, AutoMan);
            }
            CurrentListView.ListViewDestroyed += ListView_Destroyed;
            ListViewChanged(this, null);
        }
Example #5
0
 public void Dispose()
 {
     if (fDisposed)
     {
         return;
     }
     if (CurrentListView != null)
     {
         CurrentListView.Dispose();
         CurrentListView = null;
     }
     if (AutoMan != null)
     {
         AutoMan.Dispose();
         AutoMan = null;
     }
     fDisposed = true;
 }
Example #6
0
        public override bool IsTrackingItemName()
        {
            if (ShellBrowser.ViewMode != FVM.DETAILS)
            {
                return(true);
            }
            Point pt = Control.MousePosition;

            if (hotElement != null)
            {
                PInvoke.ScreenToClient(Handle, ref pt);
                return(hotElement.LabelRect.Contains(pt));
            }
            else
            {
                return(AutomationManager.DoQuery(factory => {
                    AutomationElement elem = factory.FromPoint(pt);
                    return elem != null && elem.GetAutomationId() == "System.ItemNameDisplay";
                }));
            }
        }
Example #7
0
        private void RefreshCache()
        {
            int prevItem = hotElement == null ? -1 : hotElement.Index;

            hotElement     = null;
            focusedElement = null;
            if (!IsHotTrackingEnabled())
            {
                return;
            }
            bool hasFocus = HasFocus();
            bool hasMouse = MouseIsOverListView();
            int  nextItem = AutomationManager.DoQuery(factory => {
                AutomationElement elem;
                if (hasFocus)
                {
                    elem = factory.FromKeyboardFocus();
                    if (elem != null)
                    {
                        focusedElement = new CachedListItemElement(elem, this);
                    }
                }
                if (hasMouse)
                {
                    elem = ListItemElementFromPoint(factory, Control.MousePosition);
                    if (elem == null)
                    {
                        return(-1);
                    }
                    hotElement = new CachedListItemElement(elem, this);
                    return(hotElement.Index);
                }
                return(-1);
            });

            if (nextItem != prevItem)
            {
                OnHotItemChanged(nextItem);
            }
        }
Example #8
0
 public override int HitTest(Point pt, bool ScreenCoords)
 {
     if (hotElement != null)
     {
         Point pt2 = pt;
         if (ScreenCoords)
         {
             PInvoke.ScreenToClient(Handle, ref pt2);
         }
         if (hotElement.FullRect.Contains(pt2))
         {
             return(hotElement.Index);
         }
     }
     if (!ScreenCoords)
     {
         PInvoke.ClientToScreen(Handle, ref pt);
     }
     if (subDirTip != null && subDirTip.IsShowing && subDirTip.Bounds.Contains(pt))
     {
         return(subDirIndex);
     }
     if (PInvoke.WindowFromPoint(pt) != Handle)
     {
         return(-1);
     }
     return(AutomationManager.DoQuery(factory => {
         AutomationElement elem = ListItemElementFromPoint(factory, pt);
         if (elem == null)
         {
             return -1;
         }
         hotElement = new CachedListItemElement(elem, this);
         return hotElement.Index;
     }));
 }
Example #9
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 #10
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);
            }
        }
 internal ExtendedItemsView(ShellBrowserEx ShellBrowser, IntPtr hwndShellView, IntPtr hwndListView, IntPtr hwndSubDirTipMessageReflect, AutomationManager AutoMan)
     : base(ShellBrowser, hwndShellView, hwndListView, hwndSubDirTipMessageReflect)
 {
     this.AutoMan = AutoMan;
 }