RemoteControlDevice.cs
changeset 19 d066e3999973
parent 18 24ac84ab9620
child 20 f2b65a8318e9
     1.1 --- a/RemoteControlDevice.cs	Fri Dec 05 23:18:13 2014 +0100
     1.2 +++ b/RemoteControlDevice.cs	Sat Dec 06 00:59:59 2014 +0100
     1.3 @@ -80,19 +80,38 @@
     1.4          RemoteControlButton _rcb;
     1.5  		InputDevice _device;
     1.6          MceButton iMceButton;
     1.7 +        ConsumerControl iConsumerControl;
     1.8  
     1.9          public RemoteControlEventArgs(RemoteControlButton rcb, InputDevice device)
    1.10  		{
    1.11 -            iMceButton = MceButton.Null;
    1.12 +            SetNullButtons();
    1.13 +            //
    1.14  			_rcb = rcb;
    1.15 -			_device = device;
    1.16 +			_device = device;            
    1.17  		}
    1.18  
    1.19 +        public RemoteControlEventArgs(ConsumerControl aConsumerControl, InputDevice device)
    1.20 +        {
    1.21 +            SetNullButtons();
    1.22 +            //
    1.23 +            iConsumerControl = aConsumerControl;            
    1.24 +            _device = device;
    1.25 +        }
    1.26 +
    1.27 +
    1.28          public RemoteControlEventArgs(MceButton mce, InputDevice device)
    1.29          {
    1.30 -            iMceButton = mce;
    1.31 +            SetNullButtons();
    1.32 +            //
    1.33 +            iMceButton = mce;            
    1.34 +            _device = device;
    1.35 +        }
    1.36 +
    1.37 +        private void SetNullButtons()
    1.38 +        {
    1.39 +            iConsumerControl = ConsumerControl.Null;
    1.40 +            iMceButton = MceButton.Null;
    1.41              _rcb = RemoteControlButton.Unknown;
    1.42 -            _device = device;
    1.43          }
    1.44  
    1.45  		public RemoteControlEventArgs()
    1.46 @@ -114,6 +133,12 @@
    1.47              set { iMceButton = value; }
    1.48          }
    1.49  
    1.50 +        public ConsumerControl ConsumerControl
    1.51 +        {
    1.52 +            get { return iConsumerControl; }
    1.53 +            set { iConsumerControl = value; }
    1.54 +        }
    1.55 +
    1.56  		public InputDevice Device
    1.57  		{
    1.58  			get { return _device;  }
    1.59 @@ -126,10 +151,15 @@
    1.60  
    1.61  	public sealed class RemoteControlDevice
    1.62  	{
    1.63 -		public delegate void RemoteControlDeviceEventHandler(object sender, RemoteControlEventArgs e);
    1.64 +		public delegate bool RemoteControlDeviceEventHandler(object sender, RemoteControlEventArgs e);
    1.65  		public event RemoteControlDeviceEventHandler ButtonPressed;
    1.66  
    1.67 -        public delegate void HidUsageHandler(ushort aUsage);
    1.68 +        /// <summary>
    1.69 +        /// Return true if the usage was processed.
    1.70 +        /// </summary>
    1.71 +        /// <param name="aUsage"></param>
    1.72 +        /// <returns></returns>
    1.73 +        public delegate bool HidUsageHandler(ushort aUsage);
    1.74          
    1.75  
    1.76  		//-------------------------------------------------------------
    1.77 @@ -178,11 +208,12 @@
    1.78                      ProcessKeyDown(message.WParam);
    1.79  					break;
    1.80                  case Const.WM_APPCOMMAND:
    1.81 -					ProcessAppCommand(message.LParam);
    1.82 +					//ProcessAppCommand(message.LParam);
    1.83  					break;
    1.84                  case Const.WM_INPUT:
    1.85 +                    //Returning zero means we processed that message.
    1.86 +                    message.Result = new IntPtr(0);
    1.87  					ProcessInputCommand(ref message);
    1.88 -                    message.Result = new IntPtr(0);
    1.89  					break;
    1.90  			}
    1.91  
    1.92 @@ -318,37 +349,26 @@
    1.93          /// 
    1.94          /// </summary>
    1.95          /// <param name="aUsage"></param>
    1.96 -        private void HidConsumerDeviceHandler(ushort aUsage)
    1.97 +        private bool HidConsumerDeviceHandler(ushort aUsage)
    1.98          {
    1.99              if (aUsage == 0)
   1.100              {
   1.101                  //Just skip those
   1.102 -                return;
   1.103 +                return false;
   1.104              }
   1.105  
   1.106              if (Enum.IsDefined(typeof(ConsumerControl), aUsage) && aUsage != 0) //Our button is a known consumer control
   1.107              {
   1.108                  if (this.ButtonPressed != null)
   1.109                  {
   1.110 -                    RemoteControlButton button=RemoteControlButton.Unknown;
   1.111 -                    if (aUsage == (ushort)ConsumerControl.AppCtrlProperties)
   1.112 -                    {
   1.113 -                        button = RemoteControlButton.MoreInfo;
   1.114 -                    }
   1.115 -                    else if (aUsage == (ushort)ConsumerControl.AppCtrlPrint)
   1.116 -                    {
   1.117 -                        button = RemoteControlButton.Print;
   1.118 -                    }
   1.119 -                    else if (aUsage == (ushort)ConsumerControl.MediaSelectProgramGuide)
   1.120 -                    {
   1.121 -                        button = RemoteControlButton.Guide;
   1.122 -                    }
   1.123 -                    this.ButtonPressed(this, new RemoteControlEventArgs(button, InputDevice.OEM));
   1.124 +                    return this.ButtonPressed(this, new RemoteControlEventArgs((ConsumerControl)aUsage, InputDevice.OEM));
   1.125                  }
   1.126 +                return false;
   1.127              }
   1.128              else
   1.129              {
   1.130                  Debug.WriteLine("Unknown Consumer Control!");
   1.131 +                return false;
   1.132              }
   1.133          }
   1.134  
   1.135 @@ -356,12 +376,12 @@
   1.136          /// 
   1.137          /// </summary>
   1.138          /// <param name="aUsage"></param>
   1.139 -        private void HidMceRemoteHandler(ushort aUsage)
   1.140 +        private bool HidMceRemoteHandler(ushort aUsage)
   1.141          {
   1.142              if (aUsage == 0)
   1.143              {
   1.144                  //Just skip those
   1.145 -                return;
   1.146 +                return false;
   1.147              }
   1.148  
   1.149  
   1.150 @@ -369,14 +389,15 @@
   1.151              {
   1.152                  if (this.ButtonPressed != null)
   1.153                  {
   1.154 -                    this.ButtonPressed(this, new RemoteControlEventArgs((MceButton)aUsage, InputDevice.OEM));
   1.155 +                    return this.ButtonPressed(this, new RemoteControlEventArgs((MceButton)aUsage, InputDevice.OEM));                    
   1.156                  }
   1.157 +                return false;
   1.158              }
   1.159              else
   1.160              {
   1.161                  Debug.WriteLine("Unknown MCE button!");
   1.162 +                return false;
   1.163              }
   1.164 -
   1.165          }
   1.166  
   1.167