Skip to content

Commit c8c3a96

Browse files
committed
Merge pull request #1429 from autoboosh/simplenamedefault
refactored resolver
2 parents 47c2f15 + 5b98db7 commit c8c3a96

File tree

189 files changed

+18170
-15208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+18170
-15208
lines changed

RetailCoder.VBE/Common/DeclarationExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,11 @@ public static Declaration FindTarget(this IEnumerable<Declaration> declarations,
415415
{
416416
var items = declarations.ToList();
417417

418+
// TODO: Due to the new binding mechanism this can have more than one match (e.g. in the case of index expressions + simple name expressions)
419+
// Left as is for now because the binding is not fully integrated yet.
418420
var target = items
419421
.Where(item => !item.IsBuiltIn && validDeclarationTypes.Contains(item.DeclarationType))
420-
.SingleOrDefault(item => item.IsSelected(selection)
422+
.FirstOrDefault(item => item.IsSelected(selection)
421423
|| item.References.Any(r => r.IsSelected(selection)));
422424

423425
if (target != null)

RetailCoder.VBE/Common/DeclarationIconCache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private static Uri GetIconUri(DeclarationType declarationType, Accessibility acc
159159
path = "VSObject_Enum.png";
160160
break;
161161

162-
case DeclarationType.EnumerationMember | DeclarationType.Constant:
162+
case DeclarationType.EnumerationMember:
163163
path = "VSObject_EnumItem.png";
164164
break;
165165

@@ -193,7 +193,7 @@ private static Uri GetIconUri(DeclarationType declarationType, Accessibility acc
193193
path = "VSObject_ValueType.png";
194194
break;
195195

196-
case DeclarationType.UserDefinedTypeMember | DeclarationType.Variable:
196+
case DeclarationType.UserDefinedTypeMember:
197197
path = "VSObject_Field.png";
198198
break;
199199

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public void HookHotkeys()
4545
var config = _config.LoadConfiguration();
4646
var settings = config.UserSettings.GeneralSettings.HotkeySettings;
4747

48-
_rawinput = new RawInput(_mainWindowHandle, true);
49-
_rawinput.AddMessageFilter();
48+
_rawinput = new RawInput(_mainWindowHandle);
5049

5150
var kb = (RawKeyboard)_rawinput.CreateKeyboard();
5251
_rawinput.AddDevice(kb);
@@ -69,15 +68,15 @@ private void Mouse_RawMouseInputReceived(object sender, RawMouseEventArgs e)
6968
{
7069
if (e.UlButtons.HasFlag(UsButtonFlags.RI_MOUSE_LEFT_BUTTON_UP) || e.UlButtons.HasFlag(UsButtonFlags.RI_MOUSE_RIGHT_BUTTON_UP))
7170
{
72-
MessageReceived(this, HookEventArgs.Empty);
71+
OnMessageReceived(this, HookEventArgs.Empty);
7372
}
7473
}
7574

7675
private void Keyboard_RawKeyboardInputReceived(object sender, RawKeyEventArgs e)
7776
{
7877
if (e.Message == WM.KEYUP)
7978
{
80-
MessageReceived(this, HookEventArgs.Empty);
79+
OnMessageReceived(this, HookEventArgs.Empty);
8180
}
8281
}
8382

RetailCoder.VBE/Common/WinAPI/BroadcastDeviceInterface.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

RetailCoder.VBE/Common/WinAPI/BroadcastDeviceType.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

RetailCoder.VBE/Common/WinAPI/EnumeratedDevice.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

RetailCoder.VBE/Common/WinAPI/IRawDevice.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace Rubberduck.Common.WinAPI
44
{
55
public interface IRawDevice
66
{
7-
void ProcessRawInput(IntPtr hdevice);
8-
void EnumerateDevices();
7+
void ProcessRawInput(InputData _rawBuffer);
98
}
109
}

RetailCoder.VBE/Common/WinAPI/PreMessageFilter.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

RetailCoder.VBE/Common/WinAPI/RawDevice.cs

Lines changed: 0 additions & 99 deletions
This file was deleted.
Lines changed: 14 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
24
using System.Diagnostics;
3-
using System.Windows.Forms;
45
using System.Runtime.InteropServices;
5-
using System.Collections.Generic;
6-
using Rubberduck.Common.WinAPI;
6+
using System.Windows.Forms;
77

88
namespace Rubberduck.Common.WinAPI
99
{
1010
public class RawInput : NativeWindow
1111
{
12-
readonly IntPtr _devNotifyHandle;
1312
static readonly Guid DeviceInterfaceHid = new Guid("4D1E55B2-F16F-11CF-88CB-001111000030");
14-
private PreMessageFilter _filter;
1513
private readonly List<IRawDevice> _devices;
1614

17-
public RawInput(IntPtr parentHandle, bool captureOnlyInForeground)
15+
public RawInput(IntPtr parentHandle)
1816
{
1917
AssignHandle(parentHandle);
20-
_devNotifyHandle = RegisterForDeviceNotifications(parentHandle);
2118
_devices = new List<IRawDevice>();
2219
}
2320

2421
public void AddDevice(IRawDevice device)
2522
{
2623
_devices.Add(device);
27-
device.EnumerateDevices();
2824
}
2925

3026
public IRawDevice CreateKeyboard()
@@ -35,90 +31,32 @@ public IRawDevice CreateKeyboard()
3531
public IRawDevice CreateMouse()
3632
{
3733
return new RawMouse(Handle, true);
38-
}
39-
40-
public void AddMessageFilter()
41-
{
42-
if (null != _filter)
43-
{
44-
return;
45-
}
46-
_filter = new PreMessageFilter();
47-
Application.AddMessageFilter(_filter);
48-
}
49-
50-
private void RemoveMessageFilter()
51-
{
52-
if (null == _filter)
53-
{
54-
return;
55-
}
56-
Application.RemoveMessageFilter(_filter);
57-
}
58-
59-
static IntPtr RegisterForDeviceNotifications(IntPtr parent)
60-
{
61-
var usbNotifyHandle = IntPtr.Zero;
62-
var bdi = new BroadcastDeviceInterface();
63-
bdi.DbccSize = Marshal.SizeOf(bdi);
64-
bdi.BroadcastDeviceType = BroadcastDeviceType.DBT_DEVTYP_DEVICEINTERFACE;
65-
bdi.DbccClassguid = DeviceInterfaceHid;
66-
var mem = IntPtr.Zero;
67-
try
68-
{
69-
mem = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(BroadcastDeviceInterface)));
70-
Marshal.StructureToPtr(bdi, mem, false);
71-
usbNotifyHandle = User32.RegisterDeviceNotification(parent, mem, DeviceNotification.DEVICE_NOTIFY_WINDOW_HANDLE);
72-
}
73-
catch (Exception e)
74-
{
75-
Debug.Print("Registration for device notifications Failed. Error: {0}", Marshal.GetLastWin32Error());
76-
Debug.Print(e.StackTrace);
77-
}
78-
finally
79-
{
80-
Marshal.FreeHGlobal(mem);
81-
}
82-
83-
if (usbNotifyHandle == IntPtr.Zero)
84-
{
85-
Debug.Print("Registration for device notifications Failed. Error: {0}", Marshal.GetLastWin32Error());
86-
}
87-
88-
return usbNotifyHandle;
89-
}
34+
}
9035

9136
protected override void WndProc(ref Message message)
9237
{
9338
switch ((WM)message.Msg)
9439
{
9540
case WM.INPUT:
9641
{
97-
foreach (var device in _devices)
42+
InputData _rawBuffer;
43+
var dwSize = 0;
44+
User32.GetRawInputData(message.LParam, DataCommand.RID_INPUT, IntPtr.Zero, ref dwSize, Marshal.SizeOf(typeof(RawInputHeader)));
45+
int res = User32.GetRawInputData(message.LParam, DataCommand.RID_INPUT, out _rawBuffer, ref dwSize, Marshal.SizeOf(typeof(RawInputHeader)));
46+
if (dwSize != res)
9847
{
99-
device.ProcessRawInput(message.LParam);
48+
var ex = new Win32Exception(Marshal.GetLastWin32Error());
49+
Debug.WriteLine("Error getting the rawinput buffer: {0}", ex.Message);
50+
return;
10051
}
101-
}
102-
break;
103-
104-
case WM.DEVICECHANGE:
105-
{
106-
Debug.WriteLine("USB Device Arrival / Removal");
10752
foreach (var device in _devices)
10853
{
109-
device.EnumerateDevices();
54+
device.ProcessRawInput(_rawBuffer);
11055
}
11156
}
11257
break;
11358
}
114-
11559
base.WndProc(ref message);
11660
}
117-
118-
~RawInput()
119-
{
120-
User32.UnregisterDeviceNotification(_devNotifyHandle);
121-
RemoveMessageFilter();
122-
}
12361
}
12462
}

0 commit comments

Comments
 (0)