internal ExtendedListViewCommon(ShellBrowserEx shellBrowser, IntPtr hwndShellView, IntPtr hwndListView, IntPtr hwndSubDirTipMessageReflect) {
            ShellBrowser = shellBrowser;
            this.hwndSubDirTipMessageReflect = hwndSubDirTipMessageReflect;

            ListViewController = new NativeWindowController(hwndListView);
            ListViewController.MessageCaptured += ListViewController_MessageCaptured;
            ShellViewController = new NativeWindowController(hwndShellView);
            ShellViewController.MessageCaptured += ShellViewController_MessageCaptured;

            TRACKMOUSEEVENT structure = new TRACKMOUSEEVENT();
            structure.cbSize = Marshal.SizeOf(structure);
            structure.dwFlags = 2;
            structure.hwndTrack = ListViewController.Handle;
            PInvoke.TrackMouseEvent(ref structure);

            timer_HoverSubDirTipMenu = new Timer();
            timer_HoverSubDirTipMenu.Interval = SystemInformation.MouseHoverTime * 6 / 5;
            timer_HoverSubDirTipMenu.Tick += timer_HoverSubDirTipMenu_Tick;

            hwndExplorer = PInvoke.GetAncestor(hwndShellView, 3 /* GA_ROOTOWNER */);

            // If we're late to the party, we'll have to get the IDropTarget the
            // old-fashioned way.  Careful!  Calling RegisterDragDrop will go 
            // through the hook!
            IntPtr ptr = PInvoke.GetProp(hwndListView, "OleDropTargetInterface");
            dropTargetPassthrough = TryMakeDTPassthrough(ptr);
            if(dropTargetPassthrough != null) {
                PInvoke.RevokeDragDrop(hwndListView);
                PInvoke.RegisterDragDrop(hwndListView, dropTargetPassthrough);
            }
        }
示例#2
0
 public NativeUpDown(UpDown OwnerControl) {
     CreateParams cp = new CreateParams();
     cp.ClassName = "msctls_updown32";
     cp.X = cp.Y = 0;
     cp.Width = OwnerControl.Width;
     cp.Height = OwnerControl.Height;
     cp.Parent = OwnerControl.Handle;
     cp.Style = 0x50000040;
     CreateHandle(cp);
     fTrackMouseEvent = true;
     TME = new TRACKMOUSEEVENT();
     TME.cbSize = Marshal.SizeOf(TME);
     TME.dwFlags = 2;
     TME.hwndTrack = Handle;
 }
示例#3
0
 public NativeUpDown(UpDown OwnerControl) {
     CreateParams cp = new CreateParams();
     cp.ClassName = "msctls_updown32";
     cp.X = cp.Y = 0;
     cp.Width = OwnerControl.Width;
     cp.Height = OwnerControl.Height;
     cp.Parent = OwnerControl.Handle;
     cp.Style = 0x50000040;
     this.CreateHandle(cp);
     this.fTrackMouseEvent = true;
     this.TME = new QTTabBarLib.Interop.TRACKMOUSEEVENT();
     this.TME.cbSize = Marshal.SizeOf(this.TME);
     this.TME.dwFlags = 2;
     this.TME.hwndTrack = base.Handle;
 }
示例#4
0
            public NativeUpDown(UpDown OwnerControl)
            {
                CreateParams cp = new CreateParams();

                cp.ClassName = "msctls_updown32";
                cp.X         = cp.Y = 0;
                cp.Width     = OwnerControl.Width;
                cp.Height    = OwnerControl.Height;
                cp.Parent    = OwnerControl.Handle;
                cp.Style     = 0x50000040;
                this.CreateHandle(cp);
                this.fTrackMouseEvent = true;
                this.TME           = new QTTabBarLib.Interop.TRACKMOUSEEVENT();
                this.TME.cbSize    = Marshal.SizeOf(this.TME);
                this.TME.dwFlags   = 2;
                this.TME.hwndTrack = base.Handle;
            }
        internal ExtendedListViewCommon(ShellBrowserEx shellBrowser, IntPtr hwndShellView, IntPtr hwndListView, IntPtr hwndSubDirTipMessageReflect) {
            ShellBrowser = shellBrowser;
            this.hwndSubDirTipMessageReflect = hwndSubDirTipMessageReflect;

            ListViewController = new NativeWindowController(hwndListView);
            ListViewController.MessageCaptured += ListViewController_MessageCaptured;
            ShellViewController = new NativeWindowController(hwndShellView);
            ShellViewController.MessageCaptured += ShellViewController_MessageCaptured;

            TRACKMOUSEEVENT structure = new TRACKMOUSEEVENT();
            structure.cbSize = Marshal.SizeOf(structure);
            structure.dwFlags = 2;
            structure.hwndTrack = ListViewController.Handle;
            PInvoke.TrackMouseEvent(ref structure);

            timer_HoverSubDirTipMenu = new Timer();
            timer_HoverSubDirTipMenu.Interval = SystemInformation.MouseHoverTime * 6 / 5;
            timer_HoverSubDirTipMenu.Tick += timer_HoverSubDirTipMenu_Tick;

            hwndExplorer = PInvoke.GetAncestor(hwndShellView, 3 /* GA_ROOTOWNER */);
            HookDropTarget();
        }
        private bool ShellViewController_MessageCaptured(ref System.Windows.Forms.Message msg) {
            IntPtr ptr;
            switch(msg.Msg) {
                // The ShellView is destroyed and recreated when Explorer is refreshed.
                case WM.DESTROY:
                    if(SVDestroy != null) {
                        ShellViewController.ReleaseHandle();
                        ShellViewController = null;
                        return SVDestroy();
                    }
                    break;

                case WM.MOUSEACTIVATE:
                    if(SVMouseActivate != null) {
                        int res = (int)msg.Result;
                        bool ret = SVMouseActivate(ref res);
                        msg.Result = (IntPtr)res;
                        return ret;
                    }
                    break;

                /*
            fEnteredMenuLoop is used nowhere... Unfinished feature?
            case WM.ENTERMENULOOP:
                this.fEnteredMenuLoop = true;
                break;

            case WM.EXITMENULOOP:
                this.fEnteredMenuLoop = false;
                break;
                */
            }

            if(msg.Msg != WM.NOTIFY) {
                return false;
            }

            NMHDR nmhdr = (NMHDR)Marshal.PtrToStructure(msg.LParam, typeof(NMHDR));
            if(nmhdr.hwndFrom != ListViewController.Handle) {
                if(((nmhdr.code == -12 /*NM_CUSTOMDRAW*/) && (nmhdr.idFrom == IntPtr.Zero)) && fTrackMouseEvent) {
                    fTrackMouseEvent = false;
                    TRACKMOUSEEVENT structure = new TRACKMOUSEEVENT();
                    structure.cbSize = Marshal.SizeOf(structure);
                    structure.dwFlags = 2; /*TME_LEAVE*/
                    structure.hwndTrack = ListViewController.Handle;
                    PInvoke.TrackMouseEvent(ref structure);
                }
                return false;
            }

            // Process WM.NOTIFY.  These are all notifications from the 
            // SysListView32 control.  We will not get ANY of these on 
            // Windows 7, which means every single one of them has to 
            // have an alternative somewhere for the non-SysListView32,
            // or it's not going to happen.
            switch(nmhdr.code) {
                case -12: // NM_CUSTOMDRAW
                    // This is for drawing alternating row colors.  I doubt
                    // very much we'll find an alternative for this...
                    return HandleLVCUSTOMDRAW(ref msg);

                case LVN.ITEMCHANGED: {
                        // There are three things happening here.
                        // 1. Notify plugins of selection changing: TODO
                        // 2. Redraw for Full Row Select: Not happening
                        // 3. Set new item DropHilighted: Handled in the ListView
                        //    Controller.
                        if(QTUtility.instanceManager.TryGetButtonBarHandle(this.ExplorerHandle, out ptr)) {
                            QTUtility2.SendCOPYDATASTRUCT(ptr, (IntPtr)13, null, (IntPtr)GetItemCount());
                        }
                        bool flag = QTUtility.IsVista && QTUtility.CheckConfig(Settings.NoFullRowSelect);
                        if(DropHilighted != null || SelectionChanged != null || flag) {
                            NMLISTVIEW nmlistview2 = (NMLISTVIEW)Marshal.PtrToStructure(msg.LParam, typeof(NMLISTVIEW));
                            if(nmlistview2.uChanged == 8 /*LVIF_STATE*/) {
                                uint num5 = nmlistview2.uNewState & LVIS.SELECTED;
                                uint num6 = nmlistview2.uOldState & LVIS.SELECTED;
                                uint num7 = nmlistview2.uNewState & LVIS.DROPHILITED;
                                uint num8 = nmlistview2.uOldState & LVIS.DROPHILITED;
                                uint num9 = nmlistview2.uNewState & LVIS.CUT;
                                uint num10 = nmlistview2.uOldState & LVIS.CUT;
                                if(DropHilighted != null && (num8 != num7)) {
                                    if(num7 == 0) {
                                        DropHilighted(-1);
                                    }
                                    else {
                                        DropHilighted(nmlistview2.iItem);
                                    }
                                }
                                if(flag) {
                                    if(nmlistview2.iItem != -1 && ((num5 != num6) || (num7 != num8) || (num9 != num10)) && GetCurrentViewMode() == FVM.DETAILS) {
                                        PInvoke.SendMessage(nmlistview2.hdr.hwndFrom, LVM.REDRAWITEMS, (IntPtr)nmlistview2.iItem, (IntPtr)nmlistview2.iItem);
                                    }
                                }
                                if(SelectionChanged != null && num5 != num6) {
                                    SelectionChanged();
                                }
                            }
                        }
                        break;
                    }

                case LVN.INSERTITEM:
                    ItemInserted();
                    if(QTUtility.CheckConfig(Settings.AlternateRowColors) && (GetCurrentViewMode() == FVM.DETAILS)) {
                        PInvoke.InvalidateRect(nmhdr.hwndFrom, IntPtr.Zero, true);
                    }
                    break;

                case LVN.DELETEITEM:
                    ItemDeleted();
                    if(QTUtility.CheckConfig(Settings.AlternateRowColors) && (GetCurrentViewMode() == FVM.DETAILS)) {
                        PInvoke.InvalidateRect(nmhdr.hwndFrom, IntPtr.Zero, true);
                    }
                    break;

                case LVN.DELETEALLITEMS:
                    if(AllItemsDeleted != null) return AllItemsDeleted();
                    break;

                case LVN.BEGINDRAG:
                    if(BeginDrag != null) {
                        ShellViewController.DefWndProc(ref msg);
                        BeginDrag();
                        return true;
                    }
                    break;

                case LVN.ITEMACTIVATE:
                    if(ItemActivated != null) {
                        NMITEMACTIVATE nmitemactivate = (NMITEMACTIVATE)Marshal.PtrToStructure(msg.LParam, typeof(NMITEMACTIVATE));
                        Keys modKeys =
                            (((nmitemactivate.uKeyFlags & 1) == 1) ? Keys.Alt : Keys.None) |
                            (((nmitemactivate.uKeyFlags & 2) == 2) ? Keys.Control : Keys.None) |
                            (((nmitemactivate.uKeyFlags & 4) == 4) ? Keys.Shift : Keys.None);
                        if(ItemActivated(modKeys)) return true;
                    }
                    break;

                case LVN.ODSTATECHANGED:
                    // FullRowSelect doesn't look possible anyway, so whatever.
                    if(QTUtility.IsVista && QTUtility.CheckConfig(Settings.NoFullRowSelect)) {
                        NMLVODSTATECHANGE nmlvodstatechange = (NMLVODSTATECHANGE)Marshal.PtrToStructure(msg.LParam, typeof(NMLVODSTATECHANGE));
                        if(((nmlvodstatechange.uNewState & 2) == 2) && (GetCurrentViewMode() == FVM.DETAILS)) {
                            PInvoke.SendMessage(nmlvodstatechange.hdr.hwndFrom, LVM.REDRAWITEMS, (IntPtr)nmlvodstatechange.iFrom, (IntPtr)nmlvodstatechange.iTo);
                        }
                    }
                    break;

                case LVN.HOTTRACK:
                    // This will be handled through WM_MOUSEMOVE.
                    if(HotTrack != null) {
                        NMLISTVIEW nmlistview = (NMLISTVIEW)Marshal.PtrToStructure(msg.LParam, typeof(NMLISTVIEW));
                        HotTrack(nmlistview.iItem);
                        break;
                    }
                    break;

                case LVN.KEYDOWN:
                    // This will be handled through WM_KEYDOWN.
                    if(KeyDown != null) {
                        NMLVKEYDOWN nmlvkeydown = (NMLVKEYDOWN)Marshal.PtrToStructure(msg.LParam, typeof(NMLVKEYDOWN));
                        if(KeyDown((Keys)nmlvkeydown.wVKey)) {
                            msg.Result = (IntPtr)1;
                            return true;
                        }
                        else {
                            return false;
                        }
                    }
                    break;

                case LVN.GETINFOTIP:
                    if(GetInfoTip != null) {
                        NMLVGETINFOTIP nmlvgetinfotip = (NMLVGETINFOTIP)Marshal.PtrToStructure(msg.LParam, typeof(NMLVGETINFOTIP));
                        return GetInfoTip(nmlvgetinfotip.iItem, GetHotItem() != nmlvgetinfotip.iItem); // TODO there's got to be a better way.
                    }
                    break;

                case LVN.BEGINLABELEDIT:
                    // This is just for file renaming, which there's no need to
                    // mess with in Windows 7.
                    ShellViewController.DefWndProc(ref msg);
                    if(msg.Result == IntPtr.Zero && BeginLabelEdit != null) {
                        NMLVDISPINFO nmlvdispinfo = (NMLVDISPINFO)Marshal.PtrToStructure(msg.LParam, typeof(NMLVDISPINFO));
                        BeginLabelEdit(nmlvdispinfo.item);
                    }
                    break;

                case LVN.ENDLABELEDIT:
                    if(EndLabelEdit != null) {
                        NMLVDISPINFO nmlvdispinfo2 = (NMLVDISPINFO)Marshal.PtrToStructure(msg.LParam, typeof(NMLVDISPINFO));
                        EndLabelEdit(nmlvdispinfo2.item);
                    }
                    break;

                case LVN.BEGINSCROLL:
                    // This we can handle by intercepting SBM_SETSCROLLINFO
                    // when it's sent to the scrollbars.
                    if(BeginScroll != null) {
                        return BeginScroll();
                    }
                    break;
            }
            return false;
        }
        void RecaptureHandles(IntPtr hwndShellView) {
            if(ShellViewController != null) {
                ShellViewController.ReleaseHandle();
                ShellViewController = null;
            }
            if(ListViewController != null) {
                ListViewController.ReleaseHandle();
                ListViewController = null;
            }

            ShellViewController = new NativeWindowController(hwndShellView);
            ShellViewController.MessageCaptured += new NativeWindowController.MessageEventHandler(ShellViewController_MessageCaptured);

            hwndEnumResult = IntPtr.Zero;
            PInvoke.EnumChildWindows(hwndShellView, new EnumWndProc(this.CallbackEnumChildProc_ListView), IntPtr.Zero);
            if(hwndEnumResult == IntPtr.Zero) {
                return;
            }
            
            ListViewController = new NativeWindowController(hwndEnumResult);
            ListViewController.MessageCaptured += new NativeWindowController.MessageEventHandler(ListViewController_MessageCaptured);

            if(fIsSysListView) {
                uint mask = LVS_EX.GRIDLINES | LVS_EX.FULLROWSELECT;
                uint flags = 0;
                if(QTUtility.CheckConfig(Settings.DetailsGridLines)) {
                    flags |= LVS_EX.GRIDLINES;
                }
                if(QTUtility.IsVista) {
                    if(!QTUtility.CheckConfig(Settings.NoFullRowSelect)) {
                        flags |= LVS_EX.FULLROWSELECT;
                    }
                }
                else if(QTUtility.CheckConfig(Settings.NoFullRowSelect)) {
                    if(((int)PInvoke.SendMessage(ListViewController.Handle, LVM.GETVIEW, IntPtr.Zero, IntPtr.Zero)) == 1) {
                        flags |= LVS_EX.FULLROWSELECT;
                    }
                }
                PInvoke.SendMessage(ListViewController.Handle, LVM.SETEXTENDEDLISTVIEWSTYLE, (IntPtr)mask, (IntPtr)flags);
            }
            else {
                //using(IDLWrapper wrapper = new IDLWrapper(ShellMethods.ShellGetPath(this.ShellBrowser))) {
                //    if(wrapper.IsFileSystem) {
                        AutoMan.RegisterSelChangedEvent(ListViewController.Handle, CallbackSelChanged);
                //    }
                //}
            }

            this.fTrackMouseEvent = false;
            TRACKMOUSEEVENT structure = new TRACKMOUSEEVENT();
            structure.cbSize = Marshal.SizeOf(structure);
            structure.dwFlags = 2;
            structure.hwndTrack = ListViewController.Handle;
            PInvoke.TrackMouseEvent(ref structure);
        }
        private bool ListViewController_MessageCaptured(ref System.Windows.Forms.Message msg) {

            // First block is for both SysListView and ItemsView
            switch(msg.Msg) {
                case WM.DESTROY:
                    ListViewController.ReleaseHandle();
                    ListViewController = null;
                    break;

                case WM.MOUSEMOVE:
                    if(this.fTrackMouseEvent) {
                        this.fTrackMouseEvent = false;
                        TRACKMOUSEEVENT structure = new TRACKMOUSEEVENT();
                        structure.cbSize = Marshal.SizeOf(structure);
                        structure.dwFlags = 2;
                        structure.hwndTrack = msg.HWnd;
                        PInvoke.TrackMouseEvent(ref structure);
                    }
                    break;

                case WM.LBUTTONDBLCLK:
                    if(DoubleClick != null) {
                        return DoubleClick(new Point(
                            QTUtility2.GET_X_LPARAM(msg.LParam),
                            QTUtility2.GET_Y_LPARAM(msg.LParam)));
                    }
                    break;
                
                case WM.MBUTTONUP:
                    if(MiddleClick != null) {
                        MiddleClick(new Point(
                            QTUtility2.GET_X_LPARAM(msg.LParam),
                            QTUtility2.GET_Y_LPARAM(msg.LParam)));
                    }
                    break;

                case WM.MOUSELEAVE:
                    fTrackMouseEvent = true;
                    if(MouseLeave != null) return MouseLeave();
                    break;
            }

            // From here on down is only for the ItemsView.
            if(fIsSysListView) {
                return false;
            }

            switch(msg.Msg) {
                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...
                    if(DoubleClick != null || ItemActivated != null) {
                        Int64 now = DateTime.Now.Ticks;
                        Point pt = new Point(
                            QTUtility2.GET_X_LPARAM(msg.LParam),
                            QTUtility2.GET_Y_LPARAM(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;
                                    if(DoubleClick != null && DoubleClick(pt)) {
                                        return true;
                                    }
                                    if(ItemActivated != null) {
                                        if(HitTest(pt, false) > -1) {
                                            // Explorer includes an option to make
                                            // single-clicking activate items.
                                            // TODO: Support that.
                                            if(ItemActivated(Control.ModifierKeys)) {
                                                return true;
                                            }
                                        }
                                    }
                                    return false;
                                }
                            }
                        }
                        lastLButtonPoint = pt;
                        lastLButtonTime = now;
                    }
                    return false;

                case WM.MOUSEMOVE:
                    if(HotTrack != null) {
                        Point pt = new Point(QTUtility2.GET_X_LPARAM(msg.LParam), QTUtility2.GET_Y_LPARAM(msg.LParam));
                        if(pt != lastMouseMovePoint) {
                            lastMouseMovePoint = pt;
                            return HotTrack(HitTest(pt, false));
                        }
                    }
                    break;

                case WM.KEYDOWN:
                    if(KeyDown != null && KeyDown((Keys)msg.WParam)) return true;
                    if((Keys)msg.WParam == Keys.Enter && ItemActivated != null) {
                        return ItemActivated(Control.ModifierKeys);
                    }
                    break;


                case WM.USER + 209: // This message appears to control dragging.
                    if(DropHilighted != null) {
                        Point pt = new Point((int)msg.WParam, (int)msg.LParam);
                        if(pt == lastDragPoint) {
                            return false;
                        }
                        lastDragPoint = pt;
                        return DropHilighted(HitTest(pt, false));
                    }
                    break;
                
                case WM.NOTIFY:
                    if(GetInfoTip != null) {
                        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 GetInfoTip(GetFocusedItem(), true);
                            }
                            else {
                                int i = GetHotItem();
                                if(i != -1 && IsTrackingItemName()) {
                                    return GetInfoTip(i, false);    
                                }
                            }
                        }
                    }
                    break;
            }
            return false;
        }
 private void ResetTrackMouseEvent() {
     if(fTrackMouseEvent) {
         fTrackMouseEvent = false;
         TRACKMOUSEEVENT structure = new TRACKMOUSEEVENT();
         structure.cbSize = Marshal.SizeOf(structure);
         structure.dwFlags = 2;
         structure.hwndTrack = Handle;
         PInvoke.TrackMouseEvent(ref structure);
     }
 }
示例#10
0
 public static extern bool TrackMouseEvent(ref TRACKMOUSEEVENT lpEventTrack);
示例#11
0
 public static extern bool TrackMouseEvent(ref TRACKMOUSEEVENT lpEventTrack);