- public int ReceiveCommand(CecCommand command)
- {
- return 1;
- }
-
- public int ReceiveKeypress(CecKeypress key)
- {
- SelectKeypressRow(key);
- return 1;
- }
-
- delegate void SelectKeypressRowCallback(CecKeypress key);
- private void SelectKeypressRow(CecKeypress key)
- {
- if (dgButtons.InvokeRequired)
- {
- SelectKeypressRowCallback d = new SelectKeypressRowCallback(SelectKeypressRow);
- try
- {
- this.Invoke(d, new object[] { key });
- }
- catch (Exception) { }
- }
- else
- {
- int rowIndex = -1;
- foreach (DataGridViewRow row in dgButtons.Rows)
- {
- CecButtonConfigItem item = row.DataBoundItem as CecButtonConfigItem;
- if (item != null && item.Key.Keycode == key.Keycode)
- {
- rowIndex = row.Index;
- row.Selected = true;
- item.Enabled = true;
- }
- else
- {
- row.Selected = false;
- }
- }
- if (rowIndex > -1)
- dgButtons.FirstDisplayedScrollingRowIndex = rowIndex;
- }
- }
-
- delegate void AddLogMessageCallback(CecLogMessage message);
- private void AddLogMessage(CecLogMessage message)
- {
- if (tbLog.InvokeRequired)
- {
- AddLogMessageCallback d = new AddLogMessageCallback(AddLogMessage);
- try
- {
- this.Invoke(d, new object[] { message });
- }
- catch (Exception) { }
- }
- else
- {
- string strLevel = "";
- bool display = false;
- switch (message.Level)
- {
- case CecLogLevel.Error:
- strLevel = "ERROR: ";
- display = cbLogError.Checked;
- break;
- case CecLogLevel.Warning:
- strLevel = "WARNING: ";
- display = cbLogWarning.Checked;
- break;
- case CecLogLevel.Notice:
- strLevel = "NOTICE: ";
- display = cbLogNotice.Checked;
- break;
- case CecLogLevel.Traffic:
- strLevel = "TRAFFIC: ";
- display = cbLogTraffic.Checked;
- break;
- case CecLogLevel.Debug:
- strLevel = "DEBUG: ";
- display = cbLogDebug.Checked;
- break;
- default:
- break;
- }
-
- if (display)
- {
- string strLog = string.Format("{0} {1,16} {2}", strLevel, message.Time, message.Message) + System.Environment.NewLine;
- tbLog.Text += strLog;
- tbLog.Select(tbLog.Text.Length, 0);
- tbLog.ScrollToCaret();
- }
- }
- }
-
- public int ReceiveLogMessage(CecLogMessage message)
- {
- AddLogMessage(message);
- return 1;
- }
-
- delegate void SetControlEnabledCallback(Control control, bool val);
- private void SetControlEnabled(Control control, bool val)
- {
- if (control.InvokeRequired)
- {
- SetControlEnabledCallback d = new SetControlEnabledCallback(SetControlEnabled);
- try
- {
- this.Invoke(d, new object[] { control, val });
- }
- catch (Exception) { }
- }
- else
- {
- control.Enabled = val;
- }
- }
-
- private void SetControlsEnabled(bool val)
- {
- SetControlEnabled(cbPortNumber, val);
- SetControlEnabled(cbConnectedDevice, cbConnectedDevice.Items.Count > 1 ? val : false);
- SetControlEnabled(tbPhysicalAddress, val);
- SetControlEnabled(cbDeviceType, val);
- SetControlEnabled(cbUseTVMenuLanguage, val);
- SetControlEnabled(cbPowerOnStartup, val);
- SetControlEnabled(cbPowerOffShutdown, val);
- SetControlEnabled(cbPowerOffScreensaver, val);
- SetControlEnabled(cbPowerOffOnStandby, val);
- SetControlEnabled(bClose, val);
- SetControlEnabled(bSave, val);
- }
-
- delegate void SetControlTextCallback(Control control, string val);
- private void SetControlText(Control control, string val)
- {
- if (control.InvokeRequired)
- {
- SetControlTextCallback d = new SetControlTextCallback(SetControlText);
- try
- {
- this.Invoke(d, new object[] { control, val });
- }
- catch (Exception) { }
- }
- else
- {
- control.Text = val;
- }
- }
-
- delegate void SetCheckboxCheckedCallback(CheckBox control, bool val);
- private void SetCheckboxChecked(CheckBox control, bool val)
- {
- if (control.InvokeRequired)
- {
- SetCheckboxCheckedCallback d = new SetCheckboxCheckedCallback(SetCheckboxChecked);
- try
- {
- this.Invoke(d, new object[] { control, val });
- }
- catch (Exception) { }
- }
- else
- {
- control.Checked = val;
- }
- }
-
- delegate void SetProgressValueCallback(ProgressBar control, int val);
- private void SetProgressValue(ProgressBar control, int val)
- {
- if (control.InvokeRequired)
- {
- SetProgressValueCallback d = new SetProgressValueCallback(SetProgressValue);
- try
- {
- this.Invoke(d, new object[] { control, val });
- }
- catch (Exception) { }
- }
- else
- {
- control.Value = val;
- }
- }
-
- delegate void SetComboBoxItemsCallback(ComboBox control, string selectedText, object[] val);
- private void SetComboBoxItems(ComboBox control, string selectedText, object[] val)
- {
- if (control.InvokeRequired)
- {
- SetComboBoxItemsCallback d = new SetComboBoxItemsCallback(SetComboBoxItems);
- try
- {
- this.Invoke(d, new object[] { control, selectedText, val });
- }
- catch (Exception) { }
- }
- else
- {
- control.Items.Clear();
- control.Items.AddRange(val);
- control.Text = selectedText;
- }
- }
-