# HG changeset patch # User StephaneLenclud # Date 1471788700 -7200 # Node ID afdbe76ab03b745008937401eb39bf575c828b5a # Parent 30a221eecc0605d1f75a51ddcce834066c3054f0 Ear HID event now functional. diff -r 30a221eecc06 -r afdbe76ab03b Server/Events/EventHid.cs --- a/Server/Events/EventHid.cs Sat Aug 20 21:00:35 2016 +0200 +++ b/Server/Events/EventHid.cs Sun Aug 21 16:11:40 2016 +0200 @@ -12,7 +12,7 @@ namespace SharpDisplayManager { [DataContract] - [Ear.AttributeObject(Id = "Event.Hid", Name = "HID", Description = "Corresponding HID message received.")] + [Ear.AttributeObject(Id = "Event.Hid", Name = "HID", Description = "Handle input from Keyboards and Remotes.")] public class EventHid: Ear.Event { public EventHid() @@ -62,7 +62,7 @@ public bool HasModifierWindows { get; set; } = false; [DataMember] - public string PersistedBrief { get; set; } = "Press a key"; + public string UsageName { get; set; } = "Press a key"; @@ -111,7 +111,7 @@ } else if (IsGeneric) { - brief += PersistedBrief; + brief += UsageName; } if (IsKeyUp) @@ -133,15 +133,21 @@ /// public override bool Equals(object obj) { - if (obj is EventHidKeyboard) + if (obj is EventHid) { - EventHidKeyboard e = (EventHidKeyboard)obj; + EventHid e = (EventHid)obj; return e.Key == Key - && e.IsKeyUp == IsKeyUp - && e.HasModifierAlt == HasModifierAlt - && e.HasModifierControl == HasModifierControl - && e.HasModifierShift == HasModifierShift - && e.HasModifierWindows == HasModifierWindows; + && e.Usage == Usage + && e.UsagePage == UsagePage + && e.UsageCollection == UsageCollection + && e.IsKeyUp == IsKeyUp + && e.IsGeneric == IsGeneric + && e.IsKeyboard == IsKeyboard + && e.IsMouse == IsMouse + && e.HasModifierAlt == HasModifierAlt + && e.HasModifierControl == HasModifierControl + && e.HasModifierShift == HasModifierShift + && e.HasModifierWindows == HasModifierWindows; } return false; @@ -230,7 +236,7 @@ if (aHidEvent.Usages.Count > 0) { Usage = aHidEvent.Usages[0]; - PersistedBrief = aHidEvent.UsageName(0); + UsageName = aHidEvent.UsageName(0); } Key = Keys.None; @@ -251,6 +257,13 @@ } - + /// + /// + /// + /// + public override bool IsValid() + { + return IsGeneric || IsKeyboard; + } } } diff -r 30a221eecc06 -r afdbe76ab03b Server/FormEditObject.Designer.cs --- a/Server/FormEditObject.Designer.cs Sat Aug 20 21:00:35 2016 +0200 +++ b/Server/FormEditObject.Designer.cs Sun Aug 21 16:11:40 2016 +0200 @@ -29,33 +29,35 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - this.comboBoxActionType = new System.Windows.Forms.ComboBox(); + this.iComboBoxObjectType = new System.Windows.Forms.ComboBox(); this.labelActionType = new System.Windows.Forms.Label(); - this.buttonOk = new System.Windows.Forms.Button(); + this.iButtonOk = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); this.iTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); this.toolTip = new System.Windows.Forms.ToolTip(this.components); - this.buttonTest = new System.Windows.Forms.Button(); - this.labelBrief = new System.Windows.Forms.Label(); + this.iButtonTest = new System.Windows.Forms.Button(); + this.iLabelBrief = new System.Windows.Forms.Label(); + this.iLabelDescription = new System.Windows.Forms.Label(); this.SuspendLayout(); // - // comboBoxActionType + // iComboBoxObjectType // - this.comboBoxActionType.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.iComboBoxObjectType.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.comboBoxActionType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxActionType.FormattingEnabled = true; - this.comboBoxActionType.Location = new System.Drawing.Point(55, 12); - this.comboBoxActionType.Name = "comboBoxActionType"; - this.comboBoxActionType.Size = new System.Drawing.Size(272, 21); - this.comboBoxActionType.Sorted = true; - this.comboBoxActionType.TabIndex = 18; - this.comboBoxActionType.SelectedIndexChanged += new System.EventHandler(this.comboBoxActionType_SelectedIndexChanged); + this.iComboBoxObjectType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.iComboBoxObjectType.FormattingEnabled = true; + this.iComboBoxObjectType.Location = new System.Drawing.Point(55, 52); + this.iComboBoxObjectType.Name = "iComboBoxObjectType"; + this.iComboBoxObjectType.Size = new System.Drawing.Size(272, 21); + this.iComboBoxObjectType.Sorted = true; + this.iComboBoxObjectType.TabIndex = 18; + this.iComboBoxObjectType.SelectedIndexChanged += new System.EventHandler(this.comboBoxActionType_SelectedIndexChanged); + this.iComboBoxObjectType.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.iComboBoxObjectType_KeyPress); // // labelActionType // this.labelActionType.AutoSize = true; - this.labelActionType.Location = new System.Drawing.Point(12, 15); + this.labelActionType.Location = new System.Drawing.Point(12, 55); this.labelActionType.Name = "labelActionType"; this.labelActionType.Size = new System.Drawing.Size(37, 13); this.labelActionType.TabIndex = 20; @@ -63,21 +65,21 @@ // // buttonOk // - this.buttonOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK; - this.buttonOk.Location = new System.Drawing.Point(12, 151); - this.buttonOk.Name = "buttonOk"; - this.buttonOk.Size = new System.Drawing.Size(75, 23); - this.buttonOk.TabIndex = 21; - this.buttonOk.Text = "Ok"; - this.buttonOk.UseVisualStyleBackColor = true; - this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click); + this.iButtonOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.iButtonOk.DialogResult = System.Windows.Forms.DialogResult.OK; + this.iButtonOk.Location = new System.Drawing.Point(12, 157); + this.iButtonOk.Name = "buttonOk"; + this.iButtonOk.Size = new System.Drawing.Size(75, 23); + this.iButtonOk.TabIndex = 21; + this.iButtonOk.Text = "Ok"; + this.iButtonOk.UseVisualStyleBackColor = true; + this.iButtonOk.Click += new System.EventHandler(this.buttonOk_Click); // // buttonCancel // this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.buttonCancel.Location = new System.Drawing.Point(93, 151); + this.buttonCancel.Location = new System.Drawing.Point(93, 157); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(75, 23); this.buttonCancel.TabIndex = 22; @@ -94,51 +96,65 @@ this.iTableLayoutPanel.ColumnCount = 2; this.iTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.iTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.iTableLayoutPanel.Location = new System.Drawing.Point(15, 72); + this.iTableLayoutPanel.Location = new System.Drawing.Point(15, 91); this.iTableLayoutPanel.Name = "iTableLayoutPanel"; this.iTableLayoutPanel.RowCount = 2; this.iTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.iTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.iTableLayoutPanel.Size = new System.Drawing.Size(312, 60); + this.iTableLayoutPanel.Size = new System.Drawing.Size(312, 46); this.iTableLayoutPanel.TabIndex = 23; // // buttonTest // - this.buttonTest.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonTest.Location = new System.Drawing.Point(252, 151); - this.buttonTest.Name = "buttonTest"; - this.buttonTest.Size = new System.Drawing.Size(75, 23); - this.buttonTest.TabIndex = 24; - this.buttonTest.Text = "Test"; - this.buttonTest.UseVisualStyleBackColor = true; - this.buttonTest.Click += new System.EventHandler(this.buttonTest_Click); + this.iButtonTest.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.iButtonTest.Location = new System.Drawing.Point(252, 157); + this.iButtonTest.Name = "buttonTest"; + this.iButtonTest.Size = new System.Drawing.Size(75, 23); + this.iButtonTest.TabIndex = 24; + this.iButtonTest.Text = "Test"; + this.iButtonTest.UseVisualStyleBackColor = true; + this.iButtonTest.Click += new System.EventHandler(this.buttonTest_Click); // - // labelBrief + // iLabelBrief // - this.labelBrief.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.iLabelBrief.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.labelBrief.AutoSize = true; - this.labelBrief.Location = new System.Drawing.Point(12, 45); - this.labelBrief.Name = "labelBrief"; - this.labelBrief.Size = new System.Drawing.Size(28, 13); - this.labelBrief.TabIndex = 25; - this.labelBrief.Text = "Brief"; + this.iLabelBrief.AutoSize = true; + this.iLabelBrief.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.iLabelBrief.Location = new System.Drawing.Point(12, 9); + this.iLabelBrief.Name = "iLabelBrief"; + this.iLabelBrief.Size = new System.Drawing.Size(33, 13); + this.iLabelBrief.TabIndex = 25; + this.iLabelBrief.Text = "Brief"; + // + // iLabelDescription + // + this.iLabelDescription.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.iLabelDescription.AutoSize = true; + this.iLabelDescription.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.iLabelDescription.Location = new System.Drawing.Point(12, 31); + this.iLabelDescription.Name = "iLabelDescription"; + this.iLabelDescription.Size = new System.Drawing.Size(60, 13); + this.iLabelDescription.TabIndex = 26; + this.iLabelDescription.Text = "Description"; // // FormEditObject // - this.AcceptButton = this.buttonOk; + this.AcceptButton = this.iButtonOk; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoSize = true; this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.CancelButton = this.buttonCancel; - this.ClientSize = new System.Drawing.Size(339, 186); - this.Controls.Add(this.labelBrief); - this.Controls.Add(this.buttonTest); + this.ClientSize = new System.Drawing.Size(339, 192); + this.Controls.Add(this.iLabelDescription); + this.Controls.Add(this.iLabelBrief); + this.Controls.Add(this.iButtonTest); this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.buttonOk); + this.Controls.Add(this.iButtonOk); this.Controls.Add(this.labelActionType); - this.Controls.Add(this.comboBoxActionType); + this.Controls.Add(this.iComboBoxObjectType); this.Controls.Add(this.iTableLayoutPanel); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; @@ -154,13 +170,14 @@ #endregion - private System.Windows.Forms.ComboBox comboBoxActionType; + private System.Windows.Forms.ComboBox iComboBoxObjectType; private System.Windows.Forms.Label labelActionType; - private System.Windows.Forms.Button buttonOk; + private System.Windows.Forms.Button iButtonOk; private System.Windows.Forms.Button buttonCancel; private System.Windows.Forms.TableLayoutPanel iTableLayoutPanel; private System.Windows.Forms.ToolTip toolTip; - private System.Windows.Forms.Button buttonTest; - private System.Windows.Forms.Label labelBrief; + private System.Windows.Forms.Button iButtonTest; + private System.Windows.Forms.Label iLabelBrief; + private System.Windows.Forms.Label iLabelDescription; } } \ No newline at end of file diff -r 30a221eecc06 -r afdbe76ab03b Server/FormEditObject.cs --- a/Server/FormEditObject.cs Sat Aug 20 21:00:35 2016 +0200 +++ b/Server/FormEditObject.cs Sun Aug 21 16:11:40 2016 +0200 @@ -42,42 +42,53 @@ foreach (Type type in types) { ItemObjectType item = new ItemObjectType(type); - comboBoxActionType.Items.Add(item); + iComboBoxObjectType.Items.Add(item); } if (Object == null) { // Creating new issue, select our first item - comboBoxActionType.SelectedIndex = 0; + iComboBoxObjectType.SelectedIndex = 0; } else { // Editing existing object // Look up our item in our object type combobox - foreach (ItemObjectType item in comboBoxActionType.Items) + foreach (ItemObjectType item in iComboBoxObjectType.Items) { if (item.Type == Object.GetType()) { - comboBoxActionType.SelectedItem = item; + iComboBoxObjectType.SelectedItem = item; } } } } + /// + /// + /// + /// + /// private void buttonOk_Click(object sender, EventArgs e) { FetchPropertiesValue(Object); if (!Object.IsValid()) { - // Tell for closing event to abort + // Tell closing event to cancel DialogResult = DialogResult.None; } } + /// + /// + /// + /// + /// private void FormEditObject_FormClosing(object sender, FormClosingEventArgs e) { + //Check if we need to cancel the closing of our form. e.Cancel = DialogResult == DialogResult.None; if (!e.Cancel) @@ -88,21 +99,23 @@ } } + /// + /// + /// + /// + /// private void comboBoxActionType_SelectedIndexChanged(object sender, EventArgs e) { //Instantiate an action corresponding to our type - Type actionType = ((ItemObjectType) comboBoxActionType.SelectedItem).Type; + Type actionType = ((ItemObjectType) iComboBoxObjectType.SelectedItem).Type; //Create another type of action only if needed if (Object == null || Object.GetType() != actionType) { Object = (T)Activator.CreateInstance(actionType); } - //Disable ok button if our object is not valid - buttonOk.Enabled = Object.IsValid(); - //Create input fields - UpdateTableLayoutPanel(Object); + UpdateControls(); } @@ -206,6 +219,8 @@ ctrl.Maximum = Int32.Parse(aAttribute.Maximum); ctrl.Increment = Int32.Parse(aAttribute.Increment); ctrl.Value = (int)aInfo.GetValue(aObject); + // Hook-in change notification after setting the value + ctrl.ValueChanged += ControlValueChanged; return ctrl; } else if (aInfo.PropertyType.IsEnum) @@ -238,6 +253,8 @@ enumValue = aInfo.GetValue(aObject); //Set the current item ctrl.SelectedItem = enumValue.ToString(); + // Hook-in change notification after setting the value + ctrl.SelectedIndexChanged += ControlValueChanged; return ctrl; } @@ -247,6 +264,8 @@ ctrl.AutoSize = true; ctrl.Text = aAttribute.Description; ctrl.Checked = (bool)aInfo.GetValue(aObject); + // Hook-in change notification after setting the value + ctrl.CheckedChanged += ControlValueChanged; return ctrl; } else if (aInfo.PropertyType == typeof(string)) @@ -254,6 +273,8 @@ TextBox ctrl = new TextBox(); ctrl.AutoSize = true; ctrl.Text = (string)aInfo.GetValue(aObject); + // Hook-in change notification after setting the value + ctrl.TextChanged += ControlValueChanged; return ctrl; } else if (aInfo.PropertyType == typeof(PropertyFile)) @@ -263,7 +284,6 @@ Button ctrl = new Button(); ctrl.AutoSize = true; ctrl.Text = ((PropertyFile)aInfo.GetValue(aObject)).FullPath; - // Add lambda expression to Click event ctrl.Click += (sender, e) => { @@ -277,11 +297,11 @@ { // Fetch selected file name ctrl.Text = ofd.FileName; - //Enable Ok button then - buttonOk.Enabled = Object.IsValid(); } }; + // Hook-in change notification after setting the value + ctrl.TextChanged += ControlValueChanged; return ctrl; } else if (aInfo.PropertyType == typeof(PropertyComboBox)) @@ -349,8 +369,9 @@ /// Will instantiated every field control as defined by our object. /// /// - private void UpdateTableLayoutPanel(T aObject) + private void UpdateControls() { + toolTip.RemoveAll(); //Debug.Print("UpdateTableLayoutPanel") //First clean our current panel @@ -365,20 +386,22 @@ iTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); - if (aObject == null) + if (Object == null) { //Just drop it return; } + UpdateStaticControls(); + //IEnumerable properties = aObject.GetType().GetProperties().Where( // prop => Attribute.IsDefined(prop, typeof(AttributeObjectProperty))); //TODO: Do this whenever a field changes - labelBrief.Text = Object.Brief(); + iLabelBrief.Text = Object.Brief(); - foreach (PropertyInfo pi in aObject.GetType().GetProperties()) + foreach (PropertyInfo pi in Object.GetType().GetProperties()) { AttributeObjectProperty[] attributes = ((AttributeObjectProperty[])pi.GetCustomAttributes(typeof(AttributeObjectProperty), true)); if (attributes.Length != 1) @@ -390,7 +413,7 @@ //Before anything we need to check if that kind of property is supported by our UI //Create the editor - Control ctrl = CreateControlForProperty(pi, attribute, aObject); + Control ctrl = CreateControlForProperty(pi, attribute, Object); if (ctrl == null) { //Property type not supported @@ -421,6 +444,11 @@ Object.PropertyChanged += PropertyChangedEventHandlerThreadSafe; } + /// + /// + /// + /// + /// void PropertyChangedEventHandlerThreadSafe(object sender, PropertyChangedEventArgs e) { if (this.InvokeRequired) @@ -431,16 +459,13 @@ } else { - //Disable ok button if our object is not valid - buttonOk.Enabled = Object.IsValid(); + // We could test the name of the property that has changed as follow + // It's currently not needed though + //if (e.PropertyName == "Brief") - if (e.PropertyName == "Brief") - { - labelBrief.Text = Object.Brief(); - } - - //Create input fields - //UpdateTableLayoutPanel(Object); + // Our object has changed behind our back. + // That's currently only the case for HID events that are listening for inputs. + UpdateStaticControls(); } } @@ -456,5 +481,60 @@ } } + + + /// + /// + /// + /// + /// + private void ControlValueChanged(object sender, EventArgs e) + { + UpdateObject(); + } + + /// + /// + /// + private void UpdateObject() + { + // Update our object with the content of our controls + FetchPropertiesValue(Object); + + UpdateStaticControls(); + // + //PerformLayout(); + } + + /// + /// + /// + private void UpdateStaticControls() + { + // Update OK and test button status + iButtonOk.Enabled = Object.IsValid(); + iButtonTest.Enabled = iButtonOk.Enabled; + + // Update brief title + iLabelBrief.Text = Object.Brief(); + + // Update object description + iLabelDescription.Text = Object.Description; + } + + /// + /// + /// + /// + /// + private void iComboBoxObjectType_KeyPress(object sender, KeyPressEventArgs e) + { + //Special case for HID events + if (Object is EventHid) + { + //Disable handling of key input as we are using key input for changing our event + e.Handled = true; + } + } } } diff -r 30a221eecc06 -r afdbe76ab03b Server/FormMain.Hid.cs --- a/Server/FormMain.Hid.cs Sat Aug 20 21:00:35 2016 +0200 +++ b/Server/FormMain.Hid.cs Sun Aug 21 16:11:40 2016 +0200 @@ -118,6 +118,13 @@ } else { + //Trigger corresponding EAR event if any + { + EventHid e = new EventHid(); + e.Copy(aHidEvent); + Properties.Settings.Default.EarManager.TriggerEvent(e); + } + if (aHidEvent.IsGeneric) { if (aHidEvent.Usages.Count == 0)